Javascript 从SAPUI5中的控制器动态绑定表
我已经在xml视图中创建了一个表,我想在控制器中绑定该表 因此,它可以根据加载应用程序的用户进行动态修改 XML视图Javascript 从SAPUI5中的控制器动态绑定表,javascript,odata,sapui5,Javascript,Odata,Sapui5,我已经在xml视图中创建了一个表,我想在控制器中绑定该表 因此,它可以根据加载应用程序的用户进行动态修改 XML视图 <Table inset="false" id="pTable"> <columns> <Column id="year" width="auto"> <Text text="Year" />
<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>
看起来控制器应该是这样的,但是,这不起作用
有什么建议吗 我想应该是这样的:
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集合添加项目
然后在控制器中设置模型。
在开发者工具的网络选项卡中检查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}"
})
]
}));
这就是我最终使用的解决方案,[code]var pHistory=This.byId(“pTable”);setModel(jModel);pHistory.bindAggregation(“items”、“/ratings/results”、new sap.m.ColumnListItem({cells:[new sap.m.Label({text:{Begda}}”)、new sap.m.text({text:{ratings})、new sap.m.text({text:{MwrRating}]);[/code]
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}"
})
]
}));