2017-04-11 268 views
0

所以我想用SAPUI5創建一個基本列表並在瀏覽器上顯示它。爲此我定義了Page-> app-> Data - > Model-> setData-> standadrdList-> List - > setModel - >爲頁面添加列表。這不適用於我,但沒有控制檯錯誤。然後,我確實按順序聲明瞭對象here。有人可以解釋這背後的邏輯和原因。感謝您。Javascript執行順序

var oData ={ 
    Name: "Dinasour", 
    Place : "Mammal" 
}; 

var oModel = new sap.ui.model.json.JSONModel(); 

oModel.setData(oData); 

var oItem = new sap.m.StandardListItem({ 
    title : "{/Name}", 
    description : "{/Place}" 
}); 

var oList = new sap.m.List({ 
    headerText:"List Items in a Table", 
    items:[ 
    oItem 
    ] 
}); 

oList.setModel(oModel); 

var oPage = new sap.m.Page({ 
    title:"SAP LIST", 
    content:[ 
    oList 
    ] 
}); 

var oApp = new sap.m.App({ 
    pages:[oPage] 
}).placeAt("content1"); 
+1

相關的代碼應該在這裏,而不僅僅是一個外部鏈接 –

回答

1

你沒有做正確的列表綁定。

  1. 你的數據應該像JSON
  2. 一個陣列
  3. 定義你的列表

模板,並結合路徑參見下面的代碼片段和一個工作示例here

var oData = 
[ 
    {Name: "Dinasour", Place : "Mammal"}, 
    { Name: "Dinasour2",Place : "Mammal"}, 
    { Name: "Dinasour3",Place : "Mammal"} 
]; 

//other code here 

var oItem = new sap.m.StandardListItem({ 
    title : "{Name}", 
    description : "{Place}" 
}); 


var oList = new sap.m.List({ 
    headerText:"List Items in a Table", 
    items: { 
     path: "/",  //no curly brackets here! 
     template: oItem 
    } 
}); 

//other code here