2012-10-08 65 views
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(新WebmailViewModel());

在此先感謝

+2

請添加html標記。 –

回答

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

而且,計算觀測值都意味着具有的功能中使用現有的觀測。這樣,只要在計算的可觀察值內使用的可觀察值被更新,就會調用所計算的函數。有關示例和更多信息,請參閱computed observable documentation