[英]Displaying data from JSON in SAP UI5
I am taking the Order no as input from user. 我正在接受订单号作为用户的输入。 Using this no I want to search in JSON and then display all the related data in the input texts.
使用此否,我想搜索JSON,然后在输入文本中显示所有相关数据。 [SAP UI5].
[SAP UI5]。 I do not understand how I can query on json and pull the data for rest fields.
我不明白如何查询json并提取剩余字段的数据。 I tried looking up on blogs for binding.
我试图在博客上查找绑定对象。 But I am missing some concept.
但是我缺少一些概念。 Could you please help me in understanding how to do it.
您能帮我理解如何做吗? Please review the below code.
请查看以下代码。 XML view, Data , Controller
XML视图,数据,控制器
testingagain.xml testingagain.xml
<Panel visible="true" expandable="false" headerText="Order_Info" expanded="false" width="auto" class="sapUiResponsiveMargin P2">
<content>
<VBox alignItems="Baseline">
<HBox alignItems="Center">
<items>
<Label text="Enter Order Number" labelFor="OrderNo" width="200px" />
<Input id="OrderNo" width="200px" />
<Button text="Submit" type="Accept" press="onSubmit" />
<Label text="Order Number" labelFor="OrderNo" width="200px" />
<Input id="showOrderNo" value="{OrderNo}" width="200px" />
<Label text="AccountNo" width="200px" />
<Input id="showAccNo" value="{AccountNo}" width="200px" editable="false" />
<Label text="Date of Purchase" width="200px" />
<Input id="showDate" value="{Date}" width="200px" editable="false" />
<Label text="Requested For" labelFor="searchField" textAlign="Begin" width="100px" />
<Input id="showRequestedFor1" value="{RequestedFor}" width="300px" textAlign="Center"></Input>
</items>
</HBox>
</VBox>
</content>
</Panel>
Data.json 数据.json
"OrderCollection" :[
{
"OrderNo" :"12345",
"RequestedFor" :"Arati",
"AccountNo" : "234556777",
"Date" : "Nov 19,2017",
"CC": "123345567889990985444",
"ReleaseNo" :"1232344"
},
{
"OrderNo" :"888888",
"RequestedFor" :"Arati Order 2",
"AccountNo" : "00000000",
"Date" : "Jun 21, 2017",
"CC": "88888885444",
"ReleaseNo" :"666632344"
}]
testingagain.js testingagain.js
onSubmit: function(oEvent){
var oView = this.getView();
var orderNo = oView.byId("OrderNo").getValue();
console.log(orderNo);
// here order number that I give in text field is shown on the console
var aFilters = [];
aFilters.push(new sap.ui.model.Filter("OrderNo", sap.ui.model.FilterOperator.EQ, orderNo));
//I do not know what to do here.
},
Thank you in advance. 先感谢您。
Note : id has been added to panel
注意:ID已添加到面板
<Panel visible="true" expandable="false" headerText="Order_Info" expanded="false" width="auto" class="sapUiResponsiveMargin P2" id="panel">
<content>
<VBox alignItems="Baseline">
<HBox alignItems="Center">
<items>
<Label text="Enter Order Number" labelFor="OrderNo" width="200px" />
<Input id="OrderNo" width="200px" />
<Button text="Submit" type="Accept" press="onSubmit" />
<Label text="Order Number" labelFor="OrderNo" width="200px" />
<Input id="showOrderNo" value="{OrderNo}" width="200px" />
<Label text="AccountNo" width="200px" />
<Input id="showAccNo" value="{AccountNo}" width="200px" editable="false" />
<Label text="Date of Purchase" width="200px" />
<Input id="showDate" value="{Date}" width="200px" editable="false" />
<Label text="Requested For" labelFor="searchField" textAlign="Begin" width="100px" />
<Input id="showRequestedFor1" value="{RequestedFor}" width="300px" textAlign="Center"></Input>
</items>
</HBox>
</VBox>
</content>
</Panel>
On submit function : 提交功能:
onSubmit: function(oEvent) {
var oView = this.getView();
var orderNo = oView.byId("OrderNo").getValue();
var OrderCollection = [
{
"OrderNo": "12345",
"RequestedFor": "Arati",
"AccountNo": "234556777",
"Date": "Nov 19,2017",
"CC": "123345567889990985444",
"ReleaseNo": "1232344"
},
{
"OrderNo": "888888",
"RequestedFor": "Arati Order 2",
"AccountNo": "00000000",
"Date": "Jun 21, 2017",
"CC": "88888885444",
"ReleaseNo": "666632344"
}
]
var reqObj = [];
for (var i = 0; i < OrderCollection.length; i++) {
if (OrderCollection[i].OrderNo == orderNo) {
reqObj.push(OrderCollection[i]);
break;
}
}
oView.byId("panel").setModel(new sap.ui.model.json.JSONModel(reqObj));
oView.byId("panel").bindElement("/0")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.