本文介绍了我无法在淘汰赛中应用绑定这是正确的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图模型,我想要applybindings一个视图模式是Div特定的,而另一个视图是整页的

i have two view models and i want applybindings one view modek is Div specific and the other one is full page

var profileModel = {
first: ko.observable("Bob"),
last: ko.observable("Smith")
 };

var shellModel = {
header: ko.observable("Administration"),
sections: ["profile", "settings", "notifications"],
selectedSection: ko.observable()
};

 ko.applyBindings(shellModel);
 ko.applyBindings(profileModel, document.getElementById("profile"));

推荐答案

@ Jairam,您可以创建一个具有两个视图模型的对象并将绑定应用于该对象:

Hi @Jairam you can make a object with two view model and applybindings to object:

 var profileModel = {
    first: ko.observable("Bob"),
    last: ko.observable("Smith")
     };

    var shellModel = {
    header: ko.observable("Administration"),
    sections: ["profile", "settings", "notifications"],
    selectedSection: ko.observable()
    };

    var viewModel = {
      subModelA: profileModel ,
      subModelB: shellModel 
    };

    ko.applyBindings(viewModel);

这篇关于我无法在淘汰赛中应用绑定这是正确的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 07:13