Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 敲除JSON不更新_Javascript_Json_Knockout.js - Fatal编程技术网

Javascript 敲除JSON不更新

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() {

在下面的小提琴中:

有一个名为jsonData的变量,它使用KO函数toJSON

为什么其他变量更新时它不更新? 或者甚至在调用goCaps函数时

脚本:

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));
}