2016-11-05 4 views
0

Я использую вложенный файл JSON в качестве данных макета в приложении ODATA SAPUI5, но я не могу получить доступ к вложенным данным.Вложенный JSON в макет ODATA SAPUI5

JSON содержание

[{ 
"testcase": {  
    "specification": "SRS PR 28717 – Deposit in Brazilian Reais", 
    "execution": { 
     "description": "DESC", 
     "bca_cn_acct_01": { 
      "header": { 
       "section": "Field/Section Name", 
       "data": "Data to Enter/Value to Select", 
       "action": "Activity/Check/Comment" 
      }, 
      "frame": { 
       "ID": 1, 
       "title": "Create Account: Initial Screen", 
       "data": [{ 
        "key": "Contract Start", 
        "value": "02/16/2000", 
        "action": "" 
       }, { 
        "key": "Contract Manager", 
        "value": "GH_RAMOSCL", 
        "action": "" 
       }, { 
        "key": "Product", 
        "value": "BR_IOFTC3", 
        "action": "" 
       }, { 
        "key": "Account Holder", 
        "value": "GH_IOF_COR", 
        "action": "Press Enter" 
       }] 
      } 

     } 
    }, 
    "result": "Teste" 
}}] 

В моем файле представления, я хочу, чтобы получить доступ к данным внутри тега, в виде списка:

<core:View controllerName="sap.ui.demo.MockServer.controller.App" xmlns:core="sap.ui.core" xmlns:html="http://www.w3.org/1999/xhtml" 
xmlns="sap.m"> 
<!-- <List headerText="{i18n>headerText}" id="list" items="{/Meetups}" noDataText="{i18n>noDataText}"> 
    <items> 
     <ObjectListItem number="{ path: 'EventDate', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium' } }" title="{Title}"> 
      <attributes> 
       <ObjectAttribute text="{Description}"/> 
      </attributes> 
     </ObjectListItem> 
    </items> 
</List> 
<Button press="onPressAction" text="{i18n>loadFirstItems}"></Button> --> 
<List headerText="{i18n>headerText}" id="list" items="{/Meetups}" noDataText="{i18n>noDataText}"> 
    <items> 
     <ObjectListItem number="{ path: 'EventDate', type: 'sap.ui.model.type.DateTime', formatOptions: { style: 'medium' } }" 
      title="{testcase/execution/description}"> 
      <attributes> 
       <ObjectAttribute text="{specification}"/> 
      </attributes> 
     </ObjectListItem> 
    </items> 
</List> 
<Table id="table" items="{/Meetups}"> 
    <columns> 
     <Column width="12em"> 
      <Text text="Field/Section Name"/> 
     </Column> 
     <Column minScreenWidth="Tablet" demandPopin="true"> 
      <Text text="Data to Enter/Value to Select"/> 
     </Column> 
     <Column minScreenWidth="Tablet" demandPopin="true"> 
      <Text text="Activity/Check/Comment"/> 
     </Column> 
    </columns> 
    <items> 
     <ColumnListItem> 
      <cells> 
       <ObjectIdentifier title="{testcase/execution/bca_cn_acct_01/frame/data/key}" class="sapMTableContentMargin"/> 
       <!-- <Text text="{testcase/execution/bca_cn_acct_01/bca_dte_event_begin_d}" /> --> 
       <Text text="{testcase/execution/bca_cn_acct_01/frame/data/value}"/> 
      </cells> 
     </ColumnListItem> 
    </items> 
</Table> 
<Button press="onPressAction" text="{i18n>loadFirstItems}"></Button> 

Однако данные из полей ключа и значение не извлекается как список, хотя они являются массивом внутри тега данных JSON.

я использую в качестве основы образца учебник из библиотеки SAPUI5: https://sapui5.hana.ondemand.com/#docs/guide/7a78f1b707c248fd9ec53dcb5f10814c.html

и ниже вы можешь найти файл метаданных я использую:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> 
<edmx:Edmx Version="1.0" 
    xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx"> 
    <edmx:DataServices 
     xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0"> 
     <Schema Namespace="NerdMeetup.Models" 
      xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" 
      xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
      xmlns="http://schemas.microsoft.com/ado/2006/04/edm">    
      <EntityType Name="Meetup">     
       <ComplexType Name="testcase"> 
        <ComplexType Name="execution"> 
         <!-- Create Payment Item --> 
         <ComplexType Name="bca_cn_acct_01"> 
          <ComplexType Name="header"> 
           <Property Name="section" Type="Edm.String" Nullable="false" /> 
           <Property Name="data" Type="Edm.String" Nullable="false" /> 
           <Property Name="action" Type="Edm.String" Nullable="false" /> 
          </ComplexType> 
          <ComplexType Name="frame"> 
           <Property Name="ID" Type="Edm.Int32" Nullable="false" /> 
           <Property Name="title" Type="Edm.String" Nullable="false" /> 
           <ComplexType Name="data"> 
            <Property Name="key" Type="Edm.Int32" Nullable="false" /> 
            <Property Name="value" Type="Edm.Int32" Nullable="false" /> 
            <Property Name="action" Type="Edm.Int32" Nullable="true" /> 
           </ComplexType> 
          </ComplexType> 
          <Property Name="bca_dte_event_begin_d" Type="Edm.String" Nullable="false" /> 
          <Property Name="bca_dte_orgunit_cnmgt" Type="Edm.String" Nullable="false" /> 
          <Property Name="fspr_prodext_y" Type="Edm.String" Nullable="false" /> 
          <Property Name="bca_dte_bupa_acchold" Type="Edm.String" Nullable="false" /> 
         </ComplexType> 
        </ComplexType> 
        <Property Name="specification" Type="Edm.String" Nullable="true" /> 
       </ComplexType>    
      </EntityType> 
      <EntityContainer Name="NerdMeetups" m:IsDefaultEntityContainer="true"> 
       <EntitySet Name="Meetups" EntityType="NerdMeetup.Models.Meetup" /> 
       <FunctionImport Name="FindUpcomingMeetups" EntitySet="Meetups" ReturnType="Collection(NerdMeetup.Models.Meetup)" m:HttpMethod="GET" /> 
      </EntityContainer> 
     </Schema> 
    </edmx:DataServices> 
</edmx:Edmx> 

Есть идеи?

Hugs

+1

Не могли бы вы проверить свой пример кода - в списке есть элементы = "{/ Meetups}", но в вашем JSON нет узла с именем 'meetups'. Если это не ошибка редактирования при подготовке образца, возможно, это проблема? Аналогичным образом путь для пути bjectListItem: «EventDate» представляется неправильным. В целом, я бы сказал, что на данном этапе ваш вопрос неясен. –

+0

Добавлена ​​новая информация в исходное сообщение. –

ответ

0

Я думаю, вы можете связать весь массив:

{testcase/execution/bca_cn_acct_01/frame/data/} 

Или привязать конкретный элемент массива:

{testcase/execution/bca_cn_acct_01/frame/data/0/key} 

Вы также могли бы использовать форматчик получить массив и конкатенировать все ключи массива, проверьте Formatter SAPUI5 documentation

+0

Hi Roggia, Первый вариант не работает, а второй (/ 0 /) работает, но из-за его статического характера я не могу динамически извлекать контент на основе количества существующих записей. –