簡體   English   中英

數據綁定在XML視圖中不起作用

[英]Data-binding does not work in XML view

我嘗試做一個簡單的示例:如果使用JSON視圖,則綁定有效,但是如果使用XML視圖(我更喜歡),則我有一個問題:沒有可視化的數據。 為什么?

這是控制器(等於XML和JSON視圖)

sap.ui.controller("appIntra.test", {

    onInit : function() {
        var data = {
                names: [
                    {firstName: "Peter", lastName: "Mueller"},
                    {firstName: "Petra", lastName: "Maier"},
                    {firstName: "Thomas", lastName: "Smith"},
                    {firstName: "John", lastName: "Williams"},
                    {firstName: "Maria", lastName: "Jones"}
                ]
            };
        // create a Model with this data
        var model = new sap.ui.model.json.JSONModel();
        model.setData(data);

        console.log("controller");
        sap.ui.getCore().setModel(model);
        //this.getView().setModel(model);

    },


});

這是json視圖

sap.ui.jsview("appIntra.test", {

    /** Specifies the Controller belonging to this View. 
    * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
    * @memberOf appIntra.test
    */ 
    getControllerName : function() {
        return "appIntra.test";
    },

    /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. 
    * Since the Controller is given to this method, its event handlers can be attached right away. 
    * @memberOf appIntra.test
    */ 
    createContent : function(oController) {
        console.log("view");
        // create a List control
        var list = new sap.m.List({
            headerText:"Names"
        });

        // bind the List items to the data collection
        list.bindItems({
            path : "/names", 
            template : new sap.m.StandardListItem({
                title: "{lastName}",
                description: "{firstName}",
                type: sap.m.ListType.Navigation,
            })
        });






        return new sap.m.Page({
            title: "Title",
            content: list
        });
    }

});

這是XML視圖的一部分

                    <List
                        items="{
                          path: '/items',
                          sorter: {
                            path: 'padre',
                            descending: false,
                            group: true
                          }
                        }" 
                        headerText="Operazioni" >
                        <StandardListItem
                          title="{text}" 
                        />
                    </List> 
                   <List
                    items="{
                      path: '/names',
                      sorter: {
                        path: 'padre',
                        descending: false,
                        group: true
                      }
                    }" 
                    headerText="Operazioni" >
                    <StandardListItem
                      title="{text}" 
                    />
                </List> 

請嘗試在HTML文件的bootstrap參數中添加以下參數。

數據-SAP-UI-XX-bindingSyntax = “復雜”

誠摯的問候

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM