我有一个带有4个对象的JSON模型/细节。我希望基于密钥的对象:月。
Object
oData
details:
Array[4]
0:Object
1:Object
2:Object
3:Object
editable:false
key:"date"
removeable:false
value:"Day: TRUE, Night:False"
4:Object
editable:false
key:"month"
removeable:false
value:"August"
以下是代码
/视图
var viewModel = that.getView().getModel();
var viewModelData = viewModel.getData();
答案 0 :(得分:1)
您无法直接查询对象。你必须像这样循环搜索:
var viewModel = that.getView().getModel();
var viewModelData = viewModel.getProperty("/details");
var month = getObjectByKey(viewModelData, "month");
function getObjectByKey(a, key){
for(var i = 0; i < a.length; i++){
if (a[i].key === key){
return a[i];
}
return null;
}