%
JSON ajax响应是:
function PanelViewVM() {
var self = this;
self.PanelName = ko.observable("Test");
self.PanelDetails = ko.observableArray([]),
self.SelectPanel = function () {
$.ajax("/DPanel/FillIndex", {
dataType: 'json',
contentType: 'application/json',
success: function (data) {
ko.mapping.fromJS(data.PanelDetails, {}, self.PanelDetails);
},
error: function (data) {
console.log(data);
}
});
};
self.SelectPanel();
};
ko.applyBindings(new PanelViewVM());
在地图中,我试图将PanelDetails对象返回到一个挖空阵列。
并从该数组中选择Panel并绑定到强标记
{
"PanelDetails": [
{
"PanelID": 466,
"Panel": "581ZDPAD30D",
"PanelType": 2,
"Source": "S63B",
"Substation": "S63",
"Bay": "615W",
"Voltage": 480,
"kVA": 630,
"Utility": "N",
"Train": "B",
"Circuits": 12,
"Status": "Existing/Re-fed/Re-tag",
"Drawing": "IRAE-0326"
}
],
"DPanelCcts": [
{
"PanCctID": 1442,
"PanelID": 466,
"cct": 1,
"Base": 250,
"POCID": null,
"DateUpdated": null,
"Assigned": ""
},
{
"PanCctID": 1443,
"PanelID": 466,
"cct": 2,
"Base": 400,
"POCID": 38,
"DateUpdated": "/Date(1427842800000)/",
"Assigned": "EDT113-E04"
}
] }
我不认为我正确地传递给阵列。 对于PanelDetails数组,它只有一行数据。
答案 0 :(得分:0)
我做了一个小提琴试试这个。如果您对Ajax数据的返回方式一致,那么您唯一需要做的就是更改绑定变量表示法。
Panel: <strong data-bind=" text: PanelDetails()[0].Panel">