【问题标题】:Nested each loops in jQuery templates将每个循环嵌套在 jQuery 模板中
【发布时间】:2013-06-27 14:12:54
【问题描述】:

我正在使用 Knockout 和 JQuery.tmpl 库。我的模板工作不正确。这里是:

<script type="text/html" id="filters">
    {{each(i1, item1) addedFilters}}
    <div>
        <select>
            {{each(i2, item2) filters}}
            <option value='${SystemFieldName}'
            {{if $item1 == $item2}}selected{{/if}}>
                ${Field}</option>
            {{/each}}
        </select>
        <input type="text" data-bind="value: Value" />
    </div>
    {{/each}}
</script>

问题出在 IF 语句中。它说:Uncaught ReferenceError: $item1 is not defined.

为什么?

(如果没有 if 语句,它应该可以正常工作)

【问题讨论】:

    标签: jquery knockout.js jquery-templates


    【解决方案1】:

    正确的 if 语句应该是这样的:

    {{if item1 == item2}}selected{{/if}} - 没有美元符号

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-25
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 2012-06-11
      相关资源
      最近更新 更多