来自model.read的SAPUI5填充列表

时间:2017-04-10 10:21:45

标签: json list model sapui5

我是SAPUI5开发的新手。

我试图从dymanic值填充List。

查看:

<mvc:View controllerName="porcoporcodio.controller.View1" xmlns="sap.m" xmlns:mvc="sap.ui.core.mvc" xmlns:semantic="sap.m.semantic"
xmlns:m="sap.m" xmlns:footerbar="sap.ushell.ui.footerbar" xmlns:viz="sap.viz.ui5.controls" xmlns:layout="sap.ui.layout"
xmlns:commons="sap.suite.ui.commons" xmlns:core="sap.ui.core" xmlns:f="sap.ui.layout.form">
<App>
    <pages>
        <Page title="{i18n>title}">
            <f:SimpleForm id="SimpleFormChange354" minWidth="1024" maxContainerCols="3" editable="true" layout="ResponsiveGridLayout" title="Voli"
                labelSpanL="3" labelSpanM="3" emptySpanL="4" emptySpanM="4" columnsL="1" columnsM="1" class="editableForm">
                <f:content>
                    <Label id="pene" text="Seleziona Compagnia Aerea " labelFor="combo1"></Label>
                    <ComboBox id="combo1" items="{/CarrierCollection}" selectionChange="onSelectionComboBox" showSecondaryValues= "true">
                        <core:ListItem key="{carrid}" text="{carrid}" additionalText = "{CARRNAME}" />
                    </ComboBox>
                    <Text id="Texto" >

                    </Text>
                </f:content>
            </f:SimpleForm>
<List id="lineItemsList"    items="{
  path: '/flightDetails'
                         }">
    <items>
        <StandardListItem
            title="{carrid}"
            description="{connid}"
        />
    </items>
</List>
        </Page>
    </pages>
</App>

控制器:

sap.ui.define([
  "sap/ui/core/mvc/Controller"

  ], function(Controller) {
  "use strict";

  return Controller.extend("porcoporcodio.controller.View1", {

    onInit: function() {
        var sServiceUrl = "/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/";
        var oModel = new sap.ui.model.odata.v2.ODataModel({
            serviceUrl: "/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/"
        });
        this.getView().setModel(oModel);
    },

    onSelectionComboBox: function(oEvent) {
        var pene = oEvent.getParameter("selectedItem");
        pene = pene ? pene.getText() : pene;
        var oView = this.getView();
        var sPath = "/CarrierCollection('" + pene + "')";
        var oObject = oView.getModel().getObject(sPath);
        var oTexto = oView.byId('Texto');
        oTexto.setText(oObject.CARRNAME);
        var oModel = new sap.ui.model.odata.v2.ODataModel({
            serviceUrl: "/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/"
        });
        var oStandardListItem = new sap.m.StandardListItem({
            title: "{carrid}",
            description: "{connid}"
        });
        oModel.read(sPath + "/carrierFlights", {
            method: "GET",
            success: function(data) {
                sap.m.MessageToast.show("fgfgfg");
                var json1 = new sap.ui.model.json.JSONModel();
                json1.setData({
                    carrierFlights: data
                });
                var oList = oView.byId('lineItemsList');
                oList.setModel(json1);
                oList.bindAggregation("items", "/carrierFlights", oStandardListItem);
            },
            error: function() {
                sap.m.MessageToast.show("veveveeve");
            }
        });
      }
  });
});

oModel.read看起来像工作,indise数据我可以看到我的记录,但在列表中显示什么

Image包含数据。

My model

真的感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

你应该改变:

const get = require('lodash.get');

get('first')
get('first.second')
get('first.second.third')

到:

<List id="lineItemsList" items="{path: '/carrierFlights'}">

此外:

<List id="lineItemsList" items="{path: '/flightDetails'}">

到:

oList.bindAggregation("items", "/carrierFlights", oStandardListItem);

我为你做了简单demo