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>
有什么意义?
答案 0 :(得分:1)
使用with
关键字更改范围
<template name="aName">
{{#with data}}
{{foo}} // prints "bar" as expected
{{/with}}
</template>