Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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
Meteor数据上下文-模板内没有数据#每个_Meteor - Fatal编程技术网

Meteor数据上下文-模板内没有数据#每个

Meteor数据上下文-模板内没有数据#每个,meteor,Meteor,我试着比较两个变量,看看它们是否匹配 这是为了决定我是否需要在上选择属性 模板如下所示: <select> <option disabled>Please choose...</option> {{#each themes}} <option {{selected}}>{{this.themeName}}</option> {{/each}} <

我试着比较两个变量,看看它们是否匹配

这是为了决定我是否需要在
上选择
属性

模板如下所示:

    <select>
        <option disabled>Please choose...</option>
        {{#each themes}}
            <option {{selected}}>{{this.themeName}}</option>
        {{/each}}
    </select>
问题是这里的
this
不同于
#每个
循环中的
this
,并将
{currentTheme}}
放在
#每个
中都不呈现任何内容。基本上,我无法将
currentTheme
this.themeName
进行比较,以确定它们是否相同,因为其中一个始终未定义:(

所以…我想知道我在里面要做什么

selected: function() {
    // ???
}

非常感谢!

您可以使用
UI.\u parentData()

如果这不起作用,请尝试删除“1”并放置“0”或“2”(不确定是哪个)。整数表示要通过的父视图数。

如本文所述,由于Meteor 0.8,您可以使用
关键字将父上下文作为参数传递给模板帮助器。

<select>
    <option disabled>Please choose...</option>
    {{#each themes}}
        <option {{selected ..}}>{{this.themeName}}</option>
    {{/each}}
</select>

在这种情况下,如果您只是为了这个功能而使用
currentTheme
模板帮助程序,那么它将是不必要的。

谢谢!我确实读过了,但您对我的代码的重写使我的理解具体化了。也许是我对数据上下文与变量范围的误解,但子级肯定应该继承父级上下文,如stajs中的标准变量范围?谢谢。我猜公认的答案是一个更新的接口。
selected: function() {
    // ???
    var dataOutsideEach = UI._parentData(1);

    if(currentTheme && this.theme) return "selected";

}
<select>
    <option disabled>Please choose...</option>
    {{#each themes}}
        <option {{selected ..}}>{{this.themeName}}</option>
    {{/each}}
</select>