[英]Kendo-UI Datasource is empty
我已經在kendo-ui datasoruce中對JSON數據進行了硬編碼,並希望將其傳輸到Knockout observableArray。 問題是toJSON似乎返回了一個空數組,這對我來說並不明顯,因為JSON硬編碼在dataSource的數據內部。
//The data hard-coded into the js-file
var eventsViewModel = new kendo.data.DataSource({
data:[
{ id:3,
created:1385573907907,
priority:1,
reporter:"Martin",
category:"Mähdrescher",
type:"S690",
title:"Hangausgleich defekt",
message:"Mähdrescher umgekippt",
status:"offen",
client:"Bauer",
field:"Kaiserslautern - Kohlbach",
scenario:0,
document:true,
positionLatitude:49.405703,
positionLongitude :7.423623},
{ id:1,
created:1385739507907,
priority:3,
reporter:"T670-4",
category:"Mähdrescher",
type:"T670",
title:"Hydraulikdruck unter Minimalwert",
message:"Hydraulikdruck unter 200 bar",
status:"offen",
client:"Meyer",
field:"Homburg - Auf der Höh",
scenario:0,
document :false,
positionLatitude:49.342852,
positionLongitude:6.824287},
{ id:2,
created:1385656707907,
priority:2,
reporter:"Anna",
category:"Traktor",
type:"9560RT",
title:"Kette gerissen",
message:"Linke Kette gerissen",
status:"offen",
client:"Schulze",
field:"Kaiserslautern - Feldstraße",
scenario:0,
document:false,
positionLatitude :49.402715,
positionLongitude :7.445082}
]
});
var json = eventsViewModel.data().toJSON();
console.log(JSON.stringify(json));
var events = ko.observableArray(eventsViewModel.data().toJSON());
ko.applyBindings(eventsViewModel,document.getElementById("event-view"));
一個JSbin,它顯示日志為空: http ://jsbin.com/unEPAwAn/12/edit
您需要調用eventsViewModel.read();
(即使數據是本地綁定的),也可以使用eventsViewModel.data();
訪問數據eventsViewModel.data();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.