[英]Dynamically bind table from controller in SAPUI5
我在 xml 視圖中創建了一個表,我想在控制器中綁定該表,以便可以根據加載應用程序的人員動態修改它。
XML視圖
<Table inset="false"
id="pTable">
<columns>
<Column id="year" width="auto">
<Text text="Year" />
</Column>
<Column id="rating" width="auto">
<Text text="Performance Rating"/>
</Column>
<Column id="respect" width="auto">
<Text text="Managing with Respect" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text id="tYear" text="{Begda}" />
<Text id="tRating" text="{Rating}" />
<Text id="tRespect" text="{MwrRating}" />
</cells>
</ColumnListItem>
</items>
</Table>
JS控制器
var pHistory = this.byId("pTable");
var phURL = "/PMRPerformanceSet/?$filter=IvGuid eq '5438A43913276540E1008000A7E414BA'"
pHistory.setModel(oModel);
pHistory.bindRows(phURL);
控制器看起來應該像這樣,但是,這不起作用
有什么建議?
我想它應該更像這樣:
var oTable = this.getView().byId("pTable");
var phURL = "/PMRPerformanceSet/?$filter=IvGuid eq '5438A43913276540E1008000A7E414BA'"
var oModel = new sap.ui.model.odata.ODataModel(baseUrl + phURL);
oTable.setModel(oModel);
oTable.bindRows("/YourBindingRootPath");
我猜你正在使用 sap.m.Table:
<Table id="pTable"
inset="false"
items="{/PMRPerformanceSet}"> // add items Here for your oData collection
<columns>
<Column id="year" width="auto">
<Text text="Year" />
</Column>
<Column id="rating" width="auto">
<Text text="Performance Rating"/>
</Column>
<Column id="respect" width="auto">
<Text text="Managing with Respect" />
</Column>
</columns>
<items>
<ColumnListItem>
<cells>
<Text id="tYear" text="{Begda}" />
<Text id="tRating" text="{Rating}" />
<Text id="tRespect" text="{MwrRating}" />
</cells>
</ColumnListItem>
</items>
</Table>
然后在控制器中設置模型。 在開發人員工具的網絡選項卡中檢查您的 odata 服務響應,然后根據 XML 視圖中的綁定項目。
請在控制器中試試這個
var oModel = new sap.ui.model.odata.ODataModel("proxy/http/seasrv05.applexus.com:8000/sap/opu/odata/sap/ZGET_MATERIALS",
true, 'appdevelop', 'develop01');
oModel.read("/zget_materialsCollection",null,["$filter=i_search eq 'R1' and i_werks eq '1000'"],true,
function(data, response)
{
var value=[];
value = data.results;
console.log(value);
console.log(oModel);
//sap.ui.getCore().getModel("getMaterialModel").fireRequestCompleted();
var oModel1 = new sap.ui.model.json.JSONModel();
oModel1.setData({ materials: value});
oModel1.setSizeLimit(300);
var oTable = sap.ui.getCore().byId("table");
oTable.setModel(oModel1);
oTable.bindRows("/materials");
},
function()
{
jQuery.sap.require("sap.m.MessageToast");
sap.m.MessageToast.show("No record fetched",{my : "center center",at : "center center"});
});
這是我最終使用的解決方案,它從 xml 視圖中獲取 ID 為“pTable”的表,並將其與我的 JSON 模型 jModel 綁定。
var pHistory = this.byId("pTable");
pHistory.setModel(jModel);
pHistory.bindAggregation("items", "/ratings/results", new sap.m.ColumnListItem({
cells:[
new sap.m.Label({
text:"{Begda}"
}),
new sap.m.Text({
text:"{Rating}"
}),
new sap.m.Text({
text:"{MwrRating}"
})
]
}));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.