繁体   English   中英

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

[英]Knockout containerless 'with' binding not working

这种无容器with结合不设置的BindingContext为我所期望的; 它仍然设置为包含梯形图的父级。

<!-- 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 -->

这种容器化的方法虽然工作正常。

<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>

有人知道这是怎么回事吗? Google没有给出任何结果。

问题出在Durandal,而不是Knockout,因为此答案解释了:无容器的knockoutjs语句在hottowel SPA中不起作用?

简而言之,Durandal每次视图仅允许一个根元素。

goodView.html

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

badView.html

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

谢谢@nemesv

暂无
暂无

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

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