Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用每个_Javascript_Handlebars.js - Fatal编程技术网

Javascript 使用每个

Javascript 使用每个,javascript,handlebars.js,Javascript,Handlebars.js,我只想显示id为=“firstTr-1”的第一个tr,但它应该从同一个对象获取数据,而其他tr应该有除第一个之外的数据。我应该添加任何registryhelper还是其内置的helper方法!!我查阅了文件,但没弄明白 模板: <script id="firsttemp" type="text/x-handlebars-template"> <tr id="firstTr-1"> <td class="tableFi

我只想显示id为=“firstTr-1”的第一个tr,但它应该从同一个对象获取数据,而其他tr应该有除第一个之外的数据。我应该添加任何registryhelper还是其内置的helper方法!!我查阅了文件,但没弄明白

模板:

        <script id="firsttemp" type="text/x-handlebars-template">
        <tr id="firstTr-1">

        <td class="tableFirstCol"><input type="checkbox" class="check" id="childcheck" /></td>
        <td class="tableFirstCol"><input type="checkbox" class="star" id="childstar" /></td>
        <td class="tableFirstCol"><input type="checkbox" class="alarm" id="childalarm" /></td>
        <td class="tableFirstCol">Hero Honda<span>Hero Honda</span></td>

        </tr>
        {{#each objects}}
        <tr>

        <td class="tableFirstCol"><input type="checkbox" class="check" id="childcheck" /></td>
        <td class="tableFirstCol"><input type="checkbox" class="star" id="childstar" /></td>
        <td class="tableFirstCol"><input type="checkbox" class="alarm" id="childalarm" /></td>
        <td class="tableFirstCol">{{name}}<span>{{name}}</span></td>

        </tr>{{/each}}
</script>

我觉得你把事情搞得太复杂了。Handlebar更喜欢在Handlebar看到数据之前将逻辑应用于数据。因此,与其在一个可能只在一个地方使用的自定义帮助器上乱搞,不如修改您的数据并用布尔标志标记第一个帮助器,这样您就可以在模板中执行一个简单的
{{if{u first}}
检查

模板如下所示:

<script id="firsttemp" type="text/x-handlebars-template">
    {{#each objects}}
        <tr{{#if _first}} id="firstTr-1"{{/if}}>
            <!--...-->
        </tr>
    {{/each}}
</script>
company[0]._first = true;
演示:


一旦你解决了这个问题,你就会遇到另一个问题:你正在复制复选框上的
id
属性,但是:

文档中不得有多个元素具有相同的
id

如果希望避免出现各种奇怪和令人困惑的问题,则每个复选框上都需要唯一的
id
s

company[0]._first = true;