【问题标题】:Go 'up' scope in meteor blaze?在流星大火中“上升”范围?
【发布时间】:2016-05-26 23:03:57
【问题描述】:

如何在 Blaze 中的当前范围以上的范围内使用变量?

例如:

<template name="userLayoutEditCreate">
    {{#each findUser id}}
    <h3>I am a single user (edit/create)</h3>
    <h3>{{id}}</h3>
    <form action="/" method="post">
        <fieldset>
            <!-- Primary instruments multi-select -->
            <div class="form-group">
                <label class="control-label" for="playerPrimaryInstrument">Primary instruments</label>
                <div class="controls text-left">
                    <select id="playerPrimaryInstrument" name="playerPrimaryInstrument">
                        {{#each instruments}}
                        <option value="{{name}}" {{#if equals primary_instrument name}} selected="selected" {{/if}}>{{name}}</option>
                        {{/each}}
                    </select>
                </div>
            </div>
        </fieldset>
    </form>
    {{/each}}
</template>

if 语句不在每个块中运行。但它确实在每个块之外运行(我已经定义了帮助程序)。

我得到的错误如下所示。

Reactive HTML attributes must either have a constant name or consist of a single {{helper}} providing a dictionary of names and values.  A template tag of type BLOCKOPEN is not allowed here.

==== 编辑 ====

在这种情况下,即使使用“../”范围定义也不起作用。 DID 的工作是将表达式放入所选属性的值中。我不确定这是为什么,如果您有任何想法,请告诉我?

解决办法:

{{#each instruments}}
    <option value="{{name}}" selected="{{#if equals name ../primary_instrument}} selected {{/if}}">{{name}}</option>
{{/each}}

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    试试这个:

    {{#if equals ../primary_instrument name}}
    {{/if}}
    

    【讨论】:

    • 嗨,不。那是行不通的。我正在尝试使用此代码:{{#if equals 'hi' 'hi'}} selected="selected" {{/if}}
    • 谢谢,范围的东西“../”确实有效。我已经编辑了问题以显示我遇到问题的地方
    猜你喜欢
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-15
    • 2015-09-18
    • 1970-01-01
    • 2023-03-23
    • 1970-01-01
    相关资源
    最近更新 更多