【问题标题】:SAPUI5: DataBinding to ListSAPUI5:数据绑定到列表
【发布时间】:2016-10-25 20:28:00
【问题描述】:

我有这个 XML 列表:

<List id="myList"
            items="{/Items}">
            <items>
                <ObjectListItem title="{ID}" type="Active" press="onListItemPressed"
                            number="{ parts:[{path:'Price'},{path:'Currency'}],
                            type: 'sap.ui.model.type.Currency', formatOptions: {showMeasure: false} }"
                    numberUnit="{Currency}">
                    <firstStatus>
                        <ObjectStatus
                            text="{path:'End',
                            formatter: '.formatter.getCountdown'}"
                            state="{path:'End', formatter:
                            '.formatter.getCountdownStatus'}" />
                    </firstStatus>
                    <attributes>
                        <ObjectAttribute text="{i18n>GlobalType}: {Format}" />
                    </attributes>
                </ObjectListItem>
            </items>
        </List>

目前我用JS绑定数据:

var objectTemplate = new sap.m.ObjectListItem({
                title : "{ID}",
                number : "{ parts:[{path:'Price'},{path:'Currency'}], type: 'sap.ui.model.type.Currency', formatOptions: {showMeasure: false} }",
                numberUnit :"{Currency}",
                type : sap.m.ListType.Active,
                press : this.onListItemPressed,

                attributes : [new sap.m.ObjectAttribute({
                          text : "{i18n>GlobalType}: {Format}"
                    })],
                firstStatus : new sap.m.ObjectStatus({
                                           text : "{path:'End'}",
                                           status : "{path:'End'}" 
                })
            });


oList.bindAggregation("items", {
                path : "/Items",
                filters: [ new sap.ui.model.Filter("Type", sap.ui.model.FilterOperator.EQ, oArgs.TypeID ) ],
                template : objectTemplate
      }); 

我想使用 XML 列表而不是通过 JS 创建列表。我可以将 bindAggregation 与 XML 模板一起使用吗?

【问题讨论】:

    标签: javascript xml data-binding sapui5


    【解决方案1】:

    您在第一个 XML 视图示例中以正确的方式执行此操作(您必须绑定在此示例中完成的 items 属性)。 但在这种情况下,您必须从 XML 视图中删除 &lt;items&gt; 节点,因为您想使用模板工厂而不是手动定义项目。

    <List id="myList"
            items="{/Items}">
                <ObjectListItem title="{ID}" type="Active" press="onListItemPressed"
                            number="{ parts:[{path:'Price'},{path:'Currency'}],
                            type: 'sap.ui.model.type.Currency', formatOptions: {showMeasure: false} }"
                    numberUnit="{Currency}">
                    <firstStatus>
                        <ObjectStatus
                            text="{path:'End',
                            formatter: '.formatter.getCountdown'}"
                            state="{path:'End', formatter:
                            '.formatter.getCountdownStatus'}" />
                    </firstStatus>
                    <attributes>
                        <ObjectAttribute text="{i18n>GlobalType}: {Format}" />
                    </attributes>
                </ObjectListItem>
        </List>
    

    【讨论】:

    • 但是我要在控制器中做什么而不是 template : objectTemplate ?我可以得到“myList”结构吗?我不知道在 XML 视图中使用 bindAggregation
    • AFAIK 不支持/不建议混合使用这两种技术;但是您可以尝试删除 JS 代码的 template : objectTemplate 部分,并从 XML 中删除 items="{/Items}" 绑定和 &lt;items&gt; 节点。为什么要混合这些东西?如果您想在 XML 视图中应用过滤器,请查看example
    • 我想对所有视图使用 XML。现在它是一个混合体。在 XML 中是一个没有属性的空列表,在控制器中该列表将被填充。 :-/
    • 是的,这是我们可以期待的,因为在绑定的情况下似乎不支持混合。有了这个,我建议从控制器移动到 XML view. oList.bindAggregation(..) 相当于 XML 视图中的 items="{/Items}"。在这种情况下您有任何障碍/错误吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-13
    • 2020-05-02
    • 2014-12-05
    • 1970-01-01
    相关资源
    最近更新 更多