0

次のエラーが発生しました:

エラー:バインディングを解析できません。メッセージ:ReferenceError:UpdateStatusが定義されていません。バインディング値:チェック済み:ステータス、無効化:ステータス、クリック:UpdateStatus

これが私のJavaScriptコードです

function WebmailViewModel() {
// Data
var self = this;
self.days = ['2012-10-01', '2012-10-02', '2012-10-03', '2012-10-04', '2012-10-05', '2012-10-06', '2012-10-07'];
self.choosenDateId = ko.observable();
self.choosenDateGoal = ko.observable();
self.choosenGoalId = ko.observable();

self.UpdateNote = ko.computed(function () {
    $.ajax({
        type: "POST",
        url: 'SinglePageApp.aspx/UpdateNote',
        data: "{goalId:9423}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            alert(result.d);
        }
    });
});

self.UpdateStatus = ko.computed(function () {
    $.ajax({
        type: "POST",
        url: 'SinglePageApp.aspx/UpdateStatus',
        data: "{goalId: 9423}",
        contentType: "application/json; charset=utf-8",
        success: function (result) {
            alert(result.d);
        }
    });
});

// Behaviours    
self.gotoDay = function (days) { location.hash = days };

// Client-side routes    
Sammy(function () {

    this.get('#:days', function () {          
        self.choosenDateId(this.params.days);

        debugger;
        $.ajax({
            type: "POST",
            url: 'SinglePageApp.aspx/GetGoals',
            data: "{goalDate:'" + this.params.days + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                self.choosenDateGoal(msg.d);

                alert("success");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
                alert(errorThrown);
            }
        })
    });
    this.get('', function () { this.app.runRoute('get', '#2012-10-04') });
}).run();
};

ko.applyBindings(new WebmailViewModel());

前もって感謝します

4

1 に答える 1

0

あなたの問題は、計算されたオブザーバブルを間違った意味で使用していることだと思います。関数を呼び出したい場合は(クリックバインディングにバインドしているので、必要に応じて)次のように宣言するだけです

self.<function Name> = function(< passed variables>){
    //Code to be done when this function is called.
};

計算されたものは、変数として使用されることを意味します。そのため、計算された関数に渡された関数しかない場合、それは読み取り専用の変数として扱われます。計算済みを読み取りおよび書き込み可能に指定できますが、次のような読み取りおよび書き込み関数を提供する必要があります。

self.<computed Name> = ko.computed(function(){
    read: function () {
        // return how you want this computed to be displayed.
    },
    write: function (value) {
        // How do you want this to be saved.
    },
});

また、計算されたオブザーバブルは、関数内で使用される既存のオブザーバブルを持つことを意図しています。そうすれば、計算されたオブザーバブル内で使用されるオブザーバブルが更新されるたびに、計算された関数が呼び出されます。例と詳細については、計算されたオブザーバブルのドキュメントを参照してください。

于 2012-10-08T13:42:07.990 に答える