我正在尝试将表单信息添加到我的json模型,然后在sapui5的下一个图标选项卡中显示它

时间:2014-06-20 13:30:27

标签: json model sapui5

我有一个带有名称和描述的json模型,在我的视图中我有一个图标选项卡,其中一个选项卡显示列表,接下来有一个form.i我正在尝试使用接受该表单的表单在其中添加新条目我想尝试重新列出并显示它。

我无法做到,列表没有得到刷新,它说"没有数据"。

这是我保存数据的控制器的代码。 " nonapp"是我的模特名字。

 save : function () {

   var oModel = sap.ui.getCore().getModel("nonapp");
   var newRequest = oModel.getData().Chef;
   var result = sap.ui.getCore().getModel("nonapp").getData();
   for (var i = 0 ; i < newRequest.length ; i++ ) {
        enter code hereif (newRequest[i].name === result.name) {
            newRequest[i] = result;
        }
        }
        oModel.setData({newRequest : newRequest });
oModel.refresh(true);
},

我的观点代码: -

<core:View
controllerName="view.ChefList"
xmlns="sap.m"
 xmlns:mvc="sap.ui.core.mvc"
 xmlns:l="sap.ui.layout"
 xmlns:f="sap.ui.layout.form"
 xmlns:core="sap.ui.core"
 xmlns:commons="sap.ui.commons">
 <Page
         title="{i18n>WELCOME_TITLE}"
         enableScrolling="true"
          >  

          <customHeader>
            <Bar>
                <contentLeft>
                <Button icon="sap-icon://nav-back" press="tapHomeButton" />
                </contentLeft>
            </Bar>

          </customHeader>

         <footer>
             <Bar>
             </Bar>
         </footer>
         <content>
<IconTabBar
     class="iconTabBarPaddingTop"
     id="idIconTabBarNoIcons"
     expanded="{device>/isNoPhone}">
     <items>
       <IconTabFilter
         text="Chef Details">
          <SearchField search="onSearch" width="100%" />

              <List
           id="idList"
           mode="SingleSelectMaster"
       select="onSelectionChange"
           items="{nonapp>/Chef}"
           headerText="Chef's">


              <StandardListItem
             title="{nonapp>name}"
             description="{nonapp>description}"

             iconDensityAware="false"
             iconInset="false" />
            </List>
       </IconTabFilter>
       <IconTabFilter
         text="Add Staff">
        <l:Grid
             defaultSpan="L12 M12 S12"
             width="auto">
              <l:content>
                <f:Form id="frmContact"
                  minWidth="1024"
                  maxContainerCols="2"
                >
                  <f:title>
                    <core:Title text="" />
                  </f:title>
                  <f:layout>
                    <f:ResponsiveGridLayout
                      labelSpanL="3"
                      labelSpanM="3"
                      emptySpanL="4"
                      emptySpanM="4"
                      columnsL="1"
                      columnsM="1" />
                  </f:layout>
                  <f:formContainers>
                    <f:FormContainer>
                      <f:formElements>
                        <f:FormElement label="Name" id="fname">
                          <f:fields>
                            <Input value=""  id="txtDate" enabled="true">
                              <layoutData>
                                <l:GridData span="L4 M6 S4" />
                              </layoutData>
                            </Input> 

                          </f:fields>
                        </f:FormElement>
                        <f:FormElement label="Description"id="fedescription">
                          <f:fields>
                            <Input value=""  id="txtPostDate" enabled="true">
                              <layoutData>
                                <l:GridData span="L4 M6 S4" />
                              </layoutData>
                            </Input>
                          </f:fields>
                        </f:FormElement>

                                                    <f:FormElement label="id" id="fid">
                                              <f:fields>
            <Input value=""  id="tid" enabled="true">
                                                  <layoutData>
                                                    <l:GridData span="L4 M6 S4" />
                                                  </layoutData>
                                                </Input>
                                              </f:fields>
                        </f:FormElement>
                      </f:formElements>
                    </f:FormContainer>
                  </f:formContainers>
                </f:Form>
          </l:content>
          </l:Grid>
       <HBox  alignItems="End" justifyContent="End">              
     <Button id="idButtonS" text="Create"   press="save" />
    <Button id="idButS" text="send email"   press="onEmail" />
     </HBox>
 </IconTabFilter> 
  </items>
     </IconTabBar>
   </content>
  </Page>   
</core:View>

我控制器的代码是 -     sap.ui.controller(&#34; view.ChefList&#34;,{

onInit: function() {

    this.bus = sap.ui.getCore().getEventBus();
  jQuery.sap.require("sap.m.MessageBox");
 //var model=this.getView().setModel(new sap.ui.model.json.JSONModel("model/nonapp.json"));
//  this.getView().bindElement("/Chef");
  },

  onSearch : function (oEvt) {
  var aFilters = [];
  var sQuery = oEvt.getSource().getValue();
  if (sQuery && sQuery.length > 0) {
    var filter = new sap.ui.model.Filter("name", sap.ui.model.FilterOperator.Contains,   sQuery);
   aFilters.push(filter);
   }
     var list = this.getView().byId("idList");
      var binding = list.getBinding("items");
    binding.filter(aFilters);

},
onSelectionChange : function (evt) {
var name=evt.getParameter("listItem").getBindingContext("nonapp").getObject().name;
var          des=evt.getParameter("listItem").getBindingContext("nonapp").getObject().description;
var hno=evt.getParameter("listItem").getBindingContext("nonapp").getObject().hno;
        sap.ui.getCore().getEventBus().publish("nav", "to", {
            id : "Info",
            data : {
                name:name,
                description:des,
                hno:hno
            }
        });

   },
   save : function () {

   var oModel = sap.ui.getCore().getModel("nonapp");
   var newRequest = oModel.getData().Chef;
   var result = sap.ui.getCore().getModel("nonapp").getData();
   for (var i = 0 ; i < newRequest.length ; i++ ) {
        enter code hereif (newRequest[i].name === result.name) {
            newRequest[i] = result;
        }
        }
        oModel.setData({newRequest : newRequest });
oModel.refresh(true);
},

 tapHomeButton: function(evt) {
    sap.ui.getCore().getEventBus().publish("nav", "to", {id:"StaffTile"});
},


  onEmail : function () {
 sap.m.URLHelper.triggerEmail("shivam.kapoor@marlabs.com"   , "BI", "hello");
     },

doNavBack: function(event) {
    this.bus.publish("nav", "back");
   }

 });

0 个答案:

没有答案