1. JSON Model
{ company: { name: "Treefish Inc", info: { employees: 3, }, contacts: [ { name: "Barbara", phone: "873" }, { name: "Gerry", phone: "734" }, { name: "Susan", phone: "275" } ] } }
访问路径:
/company/name /company/info/employees /company/contacts
2. OData Model
sap.ui.model.odata.ODataModel 不建议使用,使用sap.ui.model.odata.v2.ODataModel替代。
声明OData Model
1 var oModel = new sap.ui.model.odata.v2.ODataModel("http://services.odata.org/Northwind/Northwind.svc/"); 2 var oModel = new sap.ui.model.odata.v2.ODataModel({serviceUrl: "http://services.odata.org/Northwind/Northwind.svc"});
获取OData Service metadata:
var oMetadata = oModel.getServiceMetadata();
请求OData Service数据时可以添加额外的信息:
1 var oModel = new sap.ui.model.odata.v2.ODataModel({ 2 serviceUrl: "http://services.odata.org/Northwind/Northwind.svc", 3 serviceUrlParams: { 4 myParam: "value1", 5 myParam2: "value2" 6 }, 7 metadataUrlParams: { 8 myParam: "value1", 9 myParam2: "value2" 10 } 11 });
请求Service数据时 会访问
"http://myserver/MyService.svc/?myParam=value&myParam2=value2"这个路径,同理请求metadata时也是一样:(TODO)
获取数据:
1 oModel.getData("/Customer(‘ALFKI‘)"); 2 oModel.getProperty("/Customer(‘ALFKI‘)/Address");
var oData = { ProductId: 999, ProductName: "myProduct" } //POST oModel.create("/Products", oData, {success: mySuccessHandler, error: myErrorHandler}); //GET oModel.read("/Products(999)", {success: mySuccessHandler, error: myErrorHandler}); //PUT var oData = { ProductId: 999, ProductName: "myProductUpdated" } oModel.update("/Products(999)", oData, {success: mySuccessHandler, error: myErrorHandler}); //DELETE oModel.delete("/Products(999)", {success: mySuccessHandler, error: myErrorHandler});
更改完成后OModel会自动refresh
oModel.setRefreshAfterChange(false); //关闭自动刷新
TODO
3. XML Model
时间: 2024-10-07 18:05:58