【问题标题】:Data-binding does not work in XML view数据绑定在 XML 视图中不起作用
【发布时间】:2014-06-11 07:02:38
【问题描述】:

我尝试做一个简单的例子:如果我使用 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> 

【问题讨论】:

  • 好的。我解决它。我看到这个例子goo.gl/l2oQIM 我用items="{/items}" 替换items="{ path: '/items', sorter: { path: 'padre', descending: false, group: true } }" 但现在我失去了组功能......

标签: javascript xml json sapui5


【解决方案1】:
                   <List
                    items="{
                      path: '/names',
                      sorter: {
                        path: 'padre',
                        descending: false,
                        group: true
                      }
                    }" 
                    headerText="Operazioni" >
                    <StandardListItem
                      title="{text}" 
                    />
                </List> 

【讨论】:

  • 操作,我报告了一个错误的代码。如果我写一个正确的path 参考名称/xxxxx 我不会查看任何数据.. 但如果我使用items="{/xxxxx} 我有正确的结果
  • 在 xml 视图中使用 items="{/xxxxx}" 如果没有定义排序器或过滤器,/xxxxx 定义为 Path:'/xxxxx'
【解决方案2】:

请尝试在 HTML 文件的引导参数中添加以下参数。

data-sap-ui-xx-bindingSyntax="complex"

问候, 诚

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 2013-06-19
    • 1970-01-01
    • 2015-11-10
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    相关资源
    最近更新 更多