流星模板 - 如何更改数据范围?

时间:2013-05-28 09:22:50

标签: meteor handlebars.js renderpartial mustache

Meteor的模板引擎有一些我无法得到的东西,与Mustache一起使用我可以通过用{{#newscope}} {{/ newscope}封装代码来改变json数据源的范围。在实践中,这似乎与把手

的工作方式不同

这是我的模板数据源

   Template.aName.data = function()
     {
         return {"foo":"bar"};
     };

然后这是我的html模板(部分)

<template name="aName">
    {{data.foo}} // This prints "bar"

    {{#data}}
    {{foo}} // This does not prints anything but [object Object] (I expected "bar")
    {{/data}}

    {{#data.foo}}
    {{.}} // This prints "bar" but oh so ugly…
    {{/data.foo}}
</template>

有什么意义?

1 个答案:

答案 0 :(得分:1)

使用with关键字更改范围

<template name="aName">
    {{#with data}}
    {{foo}} // prints "bar" as expected
    {{/with}}
</template>
相关问题