【问题标题】:How to get every value in template which use each如何获取模板中使用每个值的每个值
【发布时间】:2015-07-19 01:04:30
【问题描述】:
<template name="mytemplate">
    {{#each work}}
        <div name="adiv">
            <input type='hidden' value={{_id}} id="testid"> <br/> 
        </div>
    {{/each}}
</template>

如果我使用 document.getElementById('testid'),它只会获取最后的值。但我想获取每个值。

【问题讨论】:

  • 通常id 在您的 HTML/DOM 树中应该是唯一的。我会使用class="testclass" 而不是保留id 仅用于唯一元素。然后你可以在模板助手中使用template.$('.testclass')docs.meteor.com/#/full/template_$

标签: templates meteor each


【解决方案1】:

这是因为 id 值是唯一的, 将 id 更改为 class,document.getElementByClassName('testid') 将返回一个数组

【讨论】:

    猜你喜欢
    • 2018-03-02
    • 1970-01-01
    • 2015-08-12
    • 2015-03-13
    • 2014-04-24
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多