如何将XML视图中的数据推送到新创建的JSON模型中?

时间:2016-04-18 11:52:04

标签: sapui5

如何将XML视图中的数据推送到新创建的JSON模型中?我创建了comboBox并从JSON模型中检索了数据,并在我在组合框中选择项目并将数据插入文本区域并提交按钮时创建了文本区域,这两个数据都应该被推送到sapweb中新创建的JSON模型ide ui5

page.view.xml:

select id_ws, duration, phases
from from v_cdco_worksite 
left join osi_phases
on v_cdco_worksite.id_ws=osi_phases.id_ws 
group by v_cdco_worksite.id_ws;

page.controller.js

<mvc:View height="100%" controllerName="pro.controller.Page" xmlns:core="sap.ui.core" xmlns:l="sap.ui.layout" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m">
    <Page title="{i18n>title}">
        <content>
            <l:VerticalLayout>
                <ComboBox items="{ path: '/ProductCollection', sorter: { path: 'Name' } }">
                    <core:Item text="{Name}" /> </ComboBox>
                <TextArea value="" rows="8" />
                <Button type="Accept" text="Submit" press="onPress" /> </l:VerticalLayout>
        </content>
    </Page>
</mvc:View>

1 个答案:

答案 0 :(得分:0)

添加一个&#39;键&#39;属于组合框项目。还给组合框和teaxarea一些ID。

<ComboBox id="selectBox" items="{ path: '/ProductCollection', sorter: { path: 'Name' } }">
                <core:Item key="{Naame}" text="{Name}" /> </ComboBox>
<TextArea id="textArea" value="" rows="8" />

点击提交后,从组合框和文本区域中获取所选值并将其推入模型中。我假设您想将这些新数据推送到现有模型,并且您现有的模型也是一个对象数组。

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;
});