【发布时间】:2014-04-30 17:39:21
【问题描述】:
Ember 遇到了一个奇怪的问题,我真的需要解决它
我有以下几点:
{{#unbound each items}}
<span>{{unbound myValue}}</span>
{{unbound view App.MyView content=this.subItems}}
{{/unbound}}
应该输出以下内容:
<div>
<span>First item</span>
<div>
...first other view...
</div>
<div>
...nth other view...
</div>
</div>
...
<div>
<span>nth item</span>
<div>
...first other view...
</div>
<div>
...nth other view...
</div>
</div>
这里有两点需要注意:
我没有使用集合处理程序...它为它创建的视图添加了一个额外的 div,我不能将它与我正在使用的插件一起使用...我 - 必须 - 保留 DOM上面需要的结构
应该没有变形标签...这个结构内部没有任何东西需要绑定,变形标签会影响我的插件的功能
现在,问题来了:我使用了上面的 '#unbound each' 助手,理论上它应该已经输出了上面的 DOM 结构。 相反我仍然从每个块中获得变形标记:
<script id="metamorph-0-start"></script>
<script id="metamorph-1-start"></script>
<div>
<span>First item</span>
<div>
...first other view...
</div>
<div>
...nth other view...
</div>
</div>
<script id="metamorph-1-end"></script>
<script id="metamorph-0-end"></script>
...
<script id="metamorph-n0-start"></script>
<script id="metamorph-n1-start"></script>
<div>
<span>nth item</span>
<div>
...first other view...
</div>
<div>
...nth other view...
</div>
</div>
<script id="metamorph-n1-end"></script>
<script id="metamorph-n0-end"></script>
我在这里做错了什么?
这是一个演示问题的现场 JS Fiddle: http://jsfiddle.net/NQKvy/942/
【问题讨论】:
-
似乎 unbound 不适用于块助手。
-
所以唯一的解决方案是使用直把手模板来渲染视图?关于阻止未绑定帮助程序最终是否计划提供此功能的任何想法?
-
可能不会,Ember Core 团队正在开发 HTMLBars,github.com/tildeio/htmlbars/commits/master,这可能会让您更接近您的解决方案。 (它本质上是通过操作 DOM 而不是使用 metamorph 标签来跟踪项目)
-
该死的,猜猜它又回到了绘图板上......不过还是谢谢
标签: javascript ember.js handlebars.js