SapUI5:如何动态地将按钮添加到CutomListItem(xml)中?

时间:2017-08-24 13:11:12

标签: sapui5

如何动态地将按钮添加到从oModel获取数据的自定义列表项?

XML:

<List  items="{msgData>/msgData}" >
<CustomListItem>
    <MessageStriptext="{msgData>Text}"></MessageStrip>


        <List  items="{msgData>buttons}">
            <CustomListItem>
                <Button  text="{text}" press="onFedYes" class="sapUiTinyMarginEnd"/>
            </CustomListItem>
        </List>


</CustomListItem>
</List>

JS:

    var oModel = this.fragment.getModel("msgData");
        var Buttons = [
            {"text": "Apple"},
            {"text": "Orange"},
            {"text": "Banana"}
        ];

            oModel.oData.msgData.push({
                Type : "Information",
                buttons:Buttons
            }); 
oModel.refresh();

更新代码

1 个答案:

答案 0 :(得分:1)

要更新模型,您的代码应该如下所示

    var oModel = this.fragment.getModel("msgData");
    var buttons = oModel.getProperty('/msgData/buttons');
    buttons.push(<..new button..>);
    oModel.setProperty('/msgData/buttons', buttons);

这将使用新添加的按钮

重新呈现列表项