2012-10-08 38 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