javascript - SAPUI5:数据绑定(bind)到列表

标签 javascript xml data-binding sapui5

我有这个 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绑定(bind)数据:

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 模板一起使用吗?

最佳答案

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

<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>

关于javascript - SAPUI5:数据绑定(bind)到列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37992720/

相关文章:

javascript - 在 d3.js 中从 csv 创建树层次结构

php - 未定义 jQuery 字符串

xml - Xquery 和开头

javascript - 将 AJAX 数据绑定(bind)到 html 列表模板

javascript - ExtJS 5 : Accessing bound store in component

javascript - 使用 MobX 状态时 Antd 模式无法打开/关闭

javascript - ajax调用后如何重新初始化slimbox2(灯箱插件)?

android - 垂直旋转 ImageView

java - DOCX4J 如何在表格中添加单元格并绑定(bind)变量

c# - 将 ListView 字段绑定(bind)到嵌套列表 WPF