【问题标题】:Meteors template - how to change the data scope?Meteors 模板 - 如何更改数据范围?
【发布时间】:2013-05-28 21:07:06
【问题描述】:

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>

有什么意义?

【问题讨论】:

    标签: meteor handlebars.js renderpartial mustache


    【解决方案1】:

    使用with 关键字更改范围

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-24
      • 2010-11-06
      • 2013-07-13
      • 2022-11-10
      • 1970-01-01
      • 2016-03-05
      • 2019-12-18
      • 2019-04-13
      相关资源
      最近更新 更多