访问模板中的数据

时间:2015-02-25 01:44:29

标签: meteor meteor-blaze

在模板中使用{{#each}}时,由于某种原因,我必须使用{{this.name}} - {{this.thing}}而不是{{name}} - {{thing}}

{{thing}}打印出正确的值,但{{name}}只是{{thing}}的副本,而不是实际打印正确的值。

如果我使用{{this.name}},则返回正确的值。

template.html
<template name="templ">
{{#each items}}
    {{name}} - {{thing}}<br/> // name == thing unless i use this.name/this.thing
{{/each}}
</template>


template.js
Template.templ.helpers({
    'items':function(){
        return Items.find(); //also tried find().fetch()
    }
});

编辑控制台输出Items.find()。fetch() [Object, Object, Object, Object, Object] 0:{ Object_id: "er2KGErydGoZBwrMc", name: "A", thing: "b.txt" }, 1:{ Object_id: "vmkgkejA3TvLZu6c6", name: "B", thing: "b.txt" }, 2:{ Object_id: "jzA2szPiakXiLibCq", name: "C", thing: "c.txt" }, 3: { Object_id: "RA29CJkgZHmhreWZo", name: "E", thing: "e.txt" }

在{{#each}}块中仅使用{{name}} - {{thing}}为每个项目呈现商品的价值。 {{this.name}}为名称呈现正确的值。

1 个答案:

答案 0 :(得分:0)

原来我有一个名为{{name}}的助手。所以{{#each}} {{name}} - {{thing}} {{/ each}}使用名称助手而不是数据上下文。

糟糕