淘汰新手,Js的新人,我是一个点网开发者,试图创建一个淘汰登录屏幕,发布数据很好,接收响应OK,只是无法弄清楚如何更新单个observable,请帮忙。 ..
function AppViewModel() {
this.email = ko.observable("Bergmail.com");
this.password = ko.observable("Password");
this.logonresult = ko.observable("logon resul");
//computed
this.Computedresult = ko.computed(function () {
return this.email() + " " + this.password();
}, this);
//behavious
this.Loginajax = function () {
var self=this
$.ajax("Indi-Dal-Json.asmx/CheckLogon" ,{
data: ko.toJSON({ email: this.email,password: this.password}),
type: "post", contentType: "application/json",
success: function (ajaxjsondata) {
{
// var parsedjson = JSON.parse(result.b);
//AppViewModel.logonresult = (result.d);
self.logonresult = ajaxjsondata.d;
}
}
});
};
}
答案 0 :(得分:1)
self.logonresult
是一个可观察的,所以你需要调用它,而不是用新值覆盖它的引用。
更改
self.logonresult = ajaxjsondata.d;
到
self.logonresult(ajaxjsondata.d);
http://knockoutjs.com/documentation/observables.html#reading_and_writing_observables
答案 1 :(得分:0)
Anders回答
self.logonresult(ajaxjsondata.d);
http://knockoutjs.com/documentation/observables.html#reading_and_writing_observables