简体   繁体   English

剔除无容器的“带有”绑定不起作用

[英]Knockout containerless 'with' binding not working

This containerless with binding doesn't set the bindingContext as I would expect; 这种无容器with结合不设置的BindingContext为我所期望的; it's still set to the containing parent of ladder. 它仍然设置为包含梯形图的父级。

<!-- ko with:ladder -->
<table>
    //Context here is the $root object, not $root.ladder
    //some foreach binding here
</table>

<a  href="#" data-bind="click: addPages">Add 4 pages</a>
<!-- /ko -->

This containerful method works fine though. 这种容器化的方法虽然工作正常。

<table class="ladder-table" data-bind="with:ladder">
    //the context is correctly set to ladder in this instance
    //some foreach binding here
</table>
<br />
<a  href="#" data-bind="click: ladder.addPages">Add 4 pages</a>

Anyone know what's up with that? 有人知道这是怎么回事吗? Google didn't give any results. Google没有给出任何结果。

The problem is with Durandal, not Knockout, as this answer explains: containerless statements of knockoutjs is not working in hottowel SPA? 问题出在Durandal,而不是Knockout,因为此答案解释了:无容器的knockoutjs语句在hottowel SPA中不起作用?

In short, Durandal allows only one root element per view. 简而言之,Durandal每次视图仅允许一个根元素。

goodView.html goodView.html

<div>
    <--ko foreach:stuff-->
      //stuff
    <--/ko-->
</div>

badView.html badView.html

<div>
   <stuff/>
</div>
<--ko foreach:stuff-->  //these elements are stripped out
  //stuff
<--/ko-->

Thanks @nemesv 谢谢@nemesv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM