如何将所选项目从输入列表项保存到 json 模型

How to save the selected item from a inputlistitem to a json model

我想将 InputListItem 中选定的列表项保存在 JSON 模型中...使用了哪个标签,如果使用了函数,那么如何进行?

<InputListItem label="Country" >
    <Select >
        <core:Item key="GR" text="Greece" />
        <core:Item key="MX" text="Mexico"/>
        <core:Item key="NO" text="Norway"/>
        <core:Item key="NZ" text="New Zealand"/>
        <core:Item key="NL" text="Netherlands"/>
    </Select>
</InputListItem>

InputListItem 只是输入控件的包装器,因此您需要查看 sap.m.Select control 中的用例(<Select> 标记)的文档。

您可能需要将 selectedKey 属性 绑定到您的模型:

<InputListItem label="Country" >
    <Select selectedKey="{model>/property}">
        <core:Item key="GR" text="Greece" />
        <!-- ... -->
    </Select>
</InputListItem>

其中 model>/property 指模型,属性 您希望将此结果绑定到。


编辑:如果你想要文本,最简单的方法是将键设置为文本本身。

例如

<core:Item key="Greece" text="Greece" />

另一种方法是在更改事件上添加侦听器,并手动将所选项目的文本添加到模型中。但这涉及更多,选择的方法取决于您要开发的内容。