How to stop knockout.js bindings evaluating on child elements

后端 未结 2 926
春和景丽
春和景丽 2020-12-15 06:24

Using knockout, when you call ko.applyBinding(viewModel, \"divId\") it does a recursive binding down through the children of the element you bound to (\"divId\"

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 07:01

    One way I have done this is to create a section for the navigation (or just a ) and bind the navVM to it. Then create another section for the content and bind the contentVM to it. That way there is no conflict and its all very separated.

    
        
        

    Then do ko.applyBinding(navVM, "navSection") and ko.applyBinding(contentVM, "contentSection")

提交回复
热议问题