Javascript 敲除JSON不更新
在下面的小提琴中: 有一个名为jsonData的变量,它使用KO函数toJSON 为什么其他变量更新时它不更新? 或者甚至在调用goCaps函数时 脚本:Javascript 敲除JSON不更新,javascript,json,knockout.js,Javascript,Json,Knockout.js,在下面的小提琴中: 有一个名为jsonData的变量,它使用KO函数toJSON 为什么其他变量更新时它不更新? 或者甚至在调用goCaps函数时 脚本: function AppViewModel() { this.firstName = ko.observable("Bert"); this.lastName = ko.observable("Bertington"); this.fullName = ko.computed(function() {
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
this.capitalizeLastName = function() {
var currentVal = this.lastName(); // Read the current value
this.lastName(currentVal.toUpperCase());
this.data = ko.toJSON(this);
};
this.data = ko.toJSON(this);
}
var appViewModel = new AppViewModel()
// Activates knockout.js
ko.applyBindings(appViewModel );
Html
姓氏:
名字:
姓氏:
全名:
盖帽
JSON:
您必须使此数据可观察:
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
this.capitalizeLastName = function() {
var currentVal = this.lastName(); // Read the current value
this.lastName(currentVal.toUpperCase());
this.data(ko.toJSON(this));
};
this.data = ko.observable(ko.toJSON(this));
}
.此。数据似乎不是可观察的。如何使其成为可观察的?
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
this.capitalizeLastName = function() {
var currentVal = this.lastName(); // Read the current value
this.lastName(currentVal.toUpperCase());
this.data(ko.toJSON(this));
};
this.data = ko.observable(ko.toJSON(this));
}