我无法访问manifest.json中定义的JSON模型。
我的JSON数据“ zCatsTestJ”看起来像这样:
{
"d": {
"results": [{
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}, {
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}]
}
}
该模型似乎可以访问,因为sJsonDate1在控制台中向我显示了数据,但我无法访问单个日期。最后,我想遍历这些日期并更改格式。
var sJsonDate1 = this.getOwnerComponent().getModel("zCatsTestJ");
var sJsonDate2 =this.getOwnerComponent().getModel("zCatsTestJ").getProperty("/d/results/1/workdate");
console.log(sJsonDate1);
console.log(sJsonDate2);
这是控制台输出,我可以在其中看到完整的数据。
但是当我尝试访问一个数据点时,它说未定义
我也直接在组件中实例化了Model,它运行良好。当我比较getOwnerComponent()和新对象中的模型对象时,它们几乎相同,除了本地对象没有aBindings
任何帮助都会受到高度重视。谢谢
答案 0 :(得分:1)
您的JSON无效,状态丢失”,并且您从不关闭数组。更正了JSON之后,我在本地尝试了此方法,并且最终效果良好。
var json = {
"d": {
"results": [
{
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}, {
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}]
}
};
var myModel = new JSONModel(json);
this.getView().setModel(myModel, "test");
this.getView().getModel("test").getProperty("/d/results/1/workdate"); "/Date(1477267200000)/"
答案 1 :(得分:0)
这是解决方案。 JsonModel不知何故太大(667个数据点),并且在调用它时未加载。这就是为什么它只处理两个条目的原因。
myModel.attachRequestCompleted(function() {
var sJsonDate = myModel.getProperty("/d/results/1/workdate");
console.log(sJsonDate);
});