Sapui5 如何将XML视图中的数据推送到新创建的JSON模型中?
如何将XML视图中的数据推送到新创建的JSON模型中?我已经创建了组合框并从JSON模型中检索了数据,当我在组合框中选择项目并将数据插入文本区域并提交按钮时,还创建了文本区域。这两个数据都应该被推送到sapweb ide ui5中新创建的JSON模型 page.view.xml:Sapui5 如何将XML视图中的数据推送到新创建的JSON模型中?,sapui5,Sapui5,如何将XML视图中的数据推送到新创建的JSON模型中?我已经创建了组合框并从JSON模型中检索了数据,当我在组合框中选择项目并将数据插入文本区域并提交按钮时,还创建了文本区域。这两个数据都应该被推送到sapweb ide ui5中新创建的JSON模型 page.view.xml: page.controller.js sap.ui.define([ “jquery.sap.global”, “sap/ui/core/mvc/Controller”, 'sap/ui/model/json/JS
page.controller.js
sap.ui.define([
“jquery.sap.global”,
“sap/ui/core/mvc/Controller”,
'sap/ui/model/json/JSONModel'
],函数(jQuery、控制器、JSONModel){
“严格使用”;
var PageController=Controller.extend(“pro.Controller.Page”{
onInit:function(){
//在此示例上设置应用程序的演示模型
var-oModel=newjsonmodel(jQuery.sap.getModulePath(“pro”,“/model/model.json”);
this.getView().setModel(oModel);
}
});
返回页控制器;
});
向组合框项添加“键”属性。也给combobox和teaxarea一些ID
<ComboBox id="selectBox" items="{ path: '/ProductCollection', sorter: { path: 'Name' } }">
<core:Item key="{Naame}" text="{Name}" /> </ComboBox>
<TextArea id="textArea" value="" rows="8" />
您好,我需要将数据推送到另一个新的json模型—存储数据的第一个json模型{“ProductCollection”:[{“key”:“Machine 123”,“Name”:“Machine 123”},{“key”:“Machine 456”,“Name”:“Machine 456”},{“key”:“Machine 790”,“Name”:“Machine 790”}]}现在,在从组合框中选择数据并在文本框中给出描述后,单击按钮应将其移动到另一个新模型。我尝试了您给出的代码,但模型没有得到更新,提交按钮上显示未捕获的TypeError:无法读取未定义的属性“getSelectedKey”是否有人告诉我如何在每次将数据推送到modelhi sarath时将数据推送到新的json模型?请解释如何合并两个json模型以及如何将输入数据推送到sapui5中的json模型
sap.ui.define([
'jquery.sap.global',
'sap/ui/core/mvc/Controller',
'sap/ui/model/json/JSONModel'
],function(jQuery, Controller, JSONModel) {
"use strict";
var PageController = Controller.extend("pro.controller.Page", {
onInit: function() {
var oModel = new JSONModel(jQuery.sap.getModulePath("pro", "/model/model.json"));
this.getView().setModel(oModel);
},
onPress: function() {
//get the value of the selected item in the combobox
var selectedVal = this.getView().byId("selectBox").getSelectedKey();
//get the textarea value
var textAreaVal = this.getView().byId("textArea").getValue();
this.getView().getModel().oData.push({
key: selectedVal,
value: textAreaVal
});
}
});
return PageController;
});