如何将可观察对象从一个命名空间视图模型更新到另一个
这不起作用,它将 defaultView 设置为“bar”,但当 ajax 请求完成时永远不会更新为“foo”。我尝试将其设置为 dependentObservable 但没有更多的运气。我是否遗漏了一些明显的东西,或者我是否试图将命名空间延伸得太远?
$.get("/players/summary", function(json) {
var playerViewModel = ko.mapping.fromJS(json);
dateViewModel.defaultDate = "foo";
ko.applyBindings(playerViewModel, 'player');
});
var dateViewModel = {
defaultDate: ko.observable("bar")
};
ko.applyBindings(dateViewModel, 'date');
This does not work, it sets the defaultView as "bar", but then never updates to "foo" when the ajax request is completed. I tried to set this as a dependentObservable but didn't have any more luck. Am I missing something obvious or am I trying to stretch namespaces too far?
$.get("/players/summary", function(json) {
var playerViewModel = ko.mapping.fromJS(json);
dateViewModel.defaultDate = "foo";
ko.applyBindings(playerViewModel, 'player');
});
var dateViewModel = {
defaultDate: ko.observable("bar")
};
ko.applyBindings(dateViewModel, 'date');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有正确设置“foo”。你应该写:
所以你有:
这应该可以解决它,但如果你仍然有问题,那么我会在你的
$.get
调用之前看看定义dateViewModel
。You are not setting "foo" correctly. You should write:
So you have:
This should fix it, but if you still have problems then I would look at definining
dateViewModel
before your$.get
call.