标签:blog io ar os sp java for on div
由于Ajax返回之后需要重新问nockout相关属性赋值,首先属性应该被定义为observable属性,在Ajax返回值之后需要重新bind,代码如下:
<script type="text/javascript"> function ViewModel() { var self = this; self.email = ko.observable(); self.password = ko.observable(); self.username = ko.observable(); self.Login = function () { $.ajax({ type: "post", dataType: "json", url: "/Home/Login/", data: { email: self.email(), password: self.password() }, success: function (json) { if (json.Result) { self.username = json.user.username; ko.applyBindings(self); $(‘.form-login‘).css(‘display‘, ‘none‘); $(‘.login-info‘).css(‘display‘,‘block‘); return false; } if (!json.Result) { alert(‘login error‘); return false; } } }); } } $(function () { var vm = new ViewModel(); ko.applyBindings(vm); }) </script>
解决nockout.js Ajax请求返回的结果,Model不能更新
标签:blog io ar os sp java for on div
原文地址:http://www.cnblogs.com/xiguain/p/4111448.html