Skip to Content
0
Former Member
Aug 16, 2015 at 08:26 AM

How to print json string from sap.ui.model.json.JSONModel and How to bind JsonModel context?

534 Views

Hi experts,

what I want is when user click the "Create" button,load json data as templet and bind JSONModel's context to detail page,bue My code doesn't woek well.

master.controller.js

handleCreate : function(evt) { var rootPath = jQuery.sap.getModulePath("cnooc.servpr.approve"); var oModel = new sap.ui.model.json.JSONModel("/model/new.json"); alert(oModel.getJSON()); var newContext = new sap.ui.model.Context(oModel, "/"); this.nav.to("Detail2", newContext); }

app.controller.js

to : function(pageId, context) { var app = this.getView().app;

// load page on demand var master = ("Master" === pageId); if (app.getPage(pageId, master) === null) { var page = sap.ui.view({ id : pageId, viewName : "cnooc.servpr.approve.view." + pageId, type : "XML" }); page.getController().nav = this; app.addPage(page, master); jQuery.sap.log.info("app controller > loaded page: " + pageId); }

// show the page app.to(pageId);

// set data context on the page if (context) { var page = app.getPage(pageId); page.setBindingContext(context); } },

who could tell me what's wrong?and how to alter json string that JSONModel loaded?

My Json file:

{

"PreqNo": "",

"PrType": "NB",

"Testrun": "",

"Commit": "",

"Eerpid": "",

"ApplicationNumber": "1234567890"

"Items": [

{

"PreqNo": "",

"PreqItem": "00010",

"DocType": "NB",

"PurGroup": "A50",

"CreatedBy": "HH_ZHAOWEI",

"PreqName": "liufang4",

"DelivDate": "2015-08-11T00:00:00",

"ShortText": "Firoi测试行项目1",

"Plant": "2293",

"Quantity": "1.000",

"Unit": "AU",

"PriceUnit": "1",

"ItemCat": "9",

"Acctasscat": "K",

"PurchOrg": "1123",

"Accounts": [

{

"PreqNo": "",

"PreqItem": "00010",

"SerialNo": "01",

"PreqQty": "1.000",

"GLAcct": "4301010099",

"CostCtr": "1442060301"

}

],

"AddrDeliverys": [],

"ServiceLines": [

{

"PreqNo": "",

"PreqItem": "00010",

"SerialNo": "01",

"ExtLine": "0000000010",

"Quantity": "1.000",

"BaseUom": "AU",

"GrPrice": "1.0000",

"ShortText": "Firoi测试服务行1"

},

{

"PreqNo": "",

"PreqItem": "00010",

"SerialNo": "01",

"ExtLine": "0000000020",

"Quantity": "10000.000",

"BaseUom": "AU",

"PriceUnit": "1",

"GrPrice": "1.0000",

"ShortText": "Firoi测试服务行2"

}

],

"TextLines": [

{

"PreqNo": "",

"PreqItem": "00010",

"TextId": "B01",

"TextForm": "",

"TextLine": "我是Firoi测试行项目文本"

}

]

}

],

"TextLines": [

{

"PreqNo": "",

"PreqItem": "00000",

"TextId": "B01",

"TextForm": "",

"TextLine": "我是Firoi测试文本"

}

]

}

Attachments