我是Knockout JS的新手。我還沒有找到谷歌在與淘汰賽js地圖上的幫助。我有一個來自服務器的JSON。我使用knockout js映射庫來映射JSON。與該屬性關聯的數據綁定dom不會更新。 我已經包含了一個即時通訊使用的小提琴。 注意被映射到observable的json對象。點擊加載按鈕時,json被映射,屬性「test」的值應該顯示在標籤中。任何想法爲什麼它不顯示在標籤中?Knockout JS不會更新映射對象
在JS小提琴中有一個工作示例。
這是被映射
var json = {
"id": 9,
"test": "John Doe",
"firstName": "John",
"lastName": "Doe",
"referenceNumber": "BUY-08",
"position": "Buyer",
"type": "Buyer",
"telephone": "028 82 240780",
"email": "[email protected]",
"departmentId": 3,
"departmentName": "DEPT B",
"country": "United Kingdom"
};
我的腳本示例
var masterModel = function()
{
var self = this;
self.members = ko.observableArray([]);
self.websites = ko.observableArray([]);
self.seoData = ko.observable();
self.test = ko.observable();
self.loadWebsite = function(website)
{
var json = {
"id": 9,
"test": "John Doe",
"firstName": "John",
"lastName": "Doe",
"referenceNumber": "BUY-08",
"position": "Buyer",
"type": "Buyer",
"telephone": "028 82 240780",
"email": "[email protected]",
"departmentId": 3,
"departmentName": "DEPT B",
"country": "United Kingdom"
};
self.test(ko.mapping.fromJS(json))
console.log(self.test);
}
}
var master = new masterModel();
ko.applyBindings(master);
問題是,當你點擊loadWebsite的$ data.test.test的JSON沒有更新!
對不起沒有發生什麼事?你的例子代碼還是其他的嗎? – 7zark7 2013-04-25 01:05:20
小提琴。數據綁定沒有被更新。 – user1566026 2013-04-25 01:07:34
更新時間/如何?什麼扭轉了更新?小提琴看起來正確 – 7zark7 2013-04-25 01:08:53