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