如何动态地将按钮添加到从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();
更新代码
答案 0 :(得分:1)
要更新模型,您的代码应该如下所示
var oModel = this.fragment.getModel("msgData");
var buttons = oModel.getProperty('/msgData/buttons');
buttons.push(<..new button..>);
oModel.setProperty('/msgData/buttons', buttons);
这将使用新添加的按钮
重新呈现列表项