Sapui5 如何检索作为InputListItem一部分且具有aggregationbinding的RadioButton的绑定属性的值?

Sapui5 如何检索作为InputListItem一部分且具有aggregationbinding的RadioButton的绑定属性的值?,sapui5,Sapui5,我在jsbin上有下面的代码,我正在尝试。我需要得到模型“answers”中提到的“Id”属性的值。直到现在,在尝试时,我才明白我需要使用select事件来警告所选值。 我还尝试使用event.getSource().getSelectedItem().getBindingContext().getObject().Id 但是我无法获取“Id”属性值。 您可以在jsbin下面找到我正在尝试的代码: 如果需要单选功能,则不必将单选按钮放在列表项中。只需利用列表的标准属性 然后,您将能够使用列表上的

我在jsbin上有下面的代码,我正在尝试。我需要得到模型“answers”中提到的“Id”属性的值。直到现在,在尝试时,我才明白我需要使用select事件来警告所选值。 我还尝试使用
event.getSource().getSelectedItem().getBindingContext().getObject().Id
但是我无法获取“Id”属性值。 您可以在jsbin下面找到我正在尝试的代码:

如果需要单选功能,则不必将单选按钮放在列表项中。只需利用列表的标准属性


然后,您将能够使用列表上的“selectionChange”事件,并按照您在问题中提到的方式获取id。

如果需要单选功能,您不必在列表项中添加单选按钮。只需利用列表的标准属性


然后,您将能够使用列表上的“selectionChange”事件,并按照您在问题中提到的方式获取id。

这将为您提供所需的信息(OnElectradio功能):

但是您在这里做了一件奇怪的事情:使用您自己构建的单选按钮来检测选择,而不是利用sapui5列表本身

您可以将列表本身与以下代码一起使用:

<List
    headerText="Awesome List"
    items="{/answers}"
    id="singleChoice"
    mode="SingleSelect"
    selectionChange="onSelectionChange">
    <items>
        <StandardListItem title="{answerText}"/>
    </items>
</List>


然后,您可以访问列表所选项目(警报(event.getSource().getSelectedItem().getBindingContext().getObject().Id);但这次是在onSelectionChange函数中)

这将为您提供所需的信息(onElectradio函数):

但是您在这里做了一件奇怪的事情:使用您自己构建的单选按钮来检测选择,而不是利用sapui5列表本身

您可以将列表本身与以下代码一起使用:

<List
    headerText="Awesome List"
    items="{/answers}"
    id="singleChoice"
    mode="SingleSelect"
    selectionChange="onSelectionChange">
    <items>
        <StandardListItem title="{answerText}"/>
    </items>
</List>


然后,您可以访问列表所选项目(警报(event.getSource().getSelectedItem().getBindingContext().getObject().Id);但这次是在onSelectionChange函数中)

您必须从绑定模型中获取
Id

将您的
OnElectradio
事件处理程序更改为以下内容:

if(!event.getParameter("selected")) return;
var oModel = event.getSource().getModel();
var sPath = event.getSource().getBindingContext().getPath()
alert(oModel.getProperty(sPath+"/Id"));

列表示例
//控制器定义
sap.ui.controller(“local.controller”{
onInit:function(){
变量oData={
“答案”:[{
“Id”:1,
“回答文字”:“猫”
}, {
“Id”:2,
“回答文字”:“兔子”
}, {
“Id”:3,
“回答文字”:“狗”
}, {
“Id”:4,
“回答文字”:“仓鼠”
}]
};
setModel(新的sap.ui.model.json.JSONModel(oData));
},
/*onSelectionChange:功能(事件){
警报(event.getSource().getSelectedItem().getBindingContext().getObject().Id);
log(JSON.stringify(event.getSource().getSelectedItem().getBindingContext().getObject());
},*/
OnElectradio:功能(事件){
如果(!event.getParameter(“selected”))返回;
var-oModel=event.getSource().getModel();
var sPath=event.getSource().getBindingContext().getPath()
警报(oModel.getProperty(sPath+“/Id”);
//警报(this.byId(“singleChoice”).getSelectedItem());
//警报(event.getSource().getSelectedItem().getBindingContext().getObject().Id);
}
});
//实例化视图,指定模型
//展示
var oView=sap.ui.xmlview({
viewContent:jQuery('#view1').html()
});
oView.placeAt(“内容”);

您必须从绑定模型获取
Id

将您的
OnElectradio
事件处理程序更改为以下内容:

if(!event.getParameter("selected")) return;
var oModel = event.getSource().getModel();
var sPath = event.getSource().getBindingContext().getPath()
alert(oModel.getProperty(sPath+"/Id"));

列表示例
//控制器定义
sap.ui.controller(“local.controller”{
onInit:function(){
变量oData={
“答案”:[{
“Id”:1,
“回答文字”:“猫”
}, {
“Id”:2,
“回答文字”:“兔子”
}, {
“Id”:3,
“回答文字”:“狗”
}, {
“Id”:4,
“回答文字”:“仓鼠”
}]
};
setModel(新的sap.ui.model.json.JSONModel(oData));
},
/*onSelectionChange:功能(事件){
警报(event.getSource().getSelectedItem().getBindingContext().getObject().Id);
log(JSON.stringify(event.getSource().getSelectedItem().getBindingContext().getObject());
},*/
OnElectradio:功能(事件){
如果(!event.getParameter(“selected”))返回;
var-oModel=event.getSource().getModel();
var sPath=event.getSource().getBindingContext().getPath()
警报(oModel.getProperty(sPath+“/Id”);
//警报(this.byId(“singleChoice”).getSelectedItem());
//警报(event.getSource().getSelectedItem().getBindingContext