数据绑定在XML视图中不起作用 [英] Data-binding does not work in XML view

查看:73
本文介绍了数据绑定在XML视图中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试做一个简单的例子:如果我使用JSON视图,绑定工作,但如果我使用XML视图(我更喜欢它),我有一个问题:没有数据可视化。为什么?

I try to do a simple example: If I use the JSON view, the binding works, but if I use the XML view (I prefer it) I have a problem: no data visualized. Why?

这是控制器(等于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> 

这篇关于数据绑定在XML视图中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆