剔除模板绑定 [英] knockout template binding

查看:105
本文介绍了剔除模板绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过模板绑定填充的ul元素.

I have an ul element which is filled through template binding.

<script type="text/html" id="someTemplate">
<li>
   <span data-bind="text: someText">
</li>
</script>

<ul data-bind="template: {foreach: someElemets, name: 'someTemplate'}">
</ul>

但是我希望第一个 li-tag不会是模板中的li-tag,而是另一个带有按钮的li-tag,并且它不会连接到someElemets数组.如果我这样做

But I want the first li-tag would not be li-tag from template but another one with button in it and it will not be connected to someElemets array. If I do in that way

<ul data-bind="template: {foreach: someElemets, name: 'someTemplate'}">
    <li><button data-bind=click: doSomething">Click me</button></li>
</ul>

然后带按钮的li-tag将是渲染后的最后一个.解决该问题的最佳方法是什么?

then li-tag with button will be the last one after rendering. What is the best way to solve that problem?

推荐答案

您可以使用无容器控制流语法,并使用注释标记进行数据绑定.无需模板. 更多信息

You can use containerless control flow syntax, databinding using comment tags. No need for a template. more info

<ul>     
    <li><button data-bind=click: doSomething">Click me</button></li>
    <!-- ko foreach: someElemets-->         
    <li>
        <span data-bind="text: someText"></span>
    </li>    
    <!-- /ko -->
</ul> 

这篇关于剔除模板绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆