2016-11-05 42 views
0

我在嵌套的數據中使用嵌套的JSON文件作爲模型數據,但我無法訪問嵌套的數據。ODATA中的嵌套JSON 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> 

任何想法?

擁抱

+1

你能否檢查你的示例代碼 - 列表似乎有items =「{/ 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 /)可以工作,但由於其靜態性質,我不能根據現有條目的數量提取內容。 –