Meteor - HTML属性错误中不允许使用TRIPLE模板标记

时间:2014-04-07 08:08:18

标签: meteor meteorite

尝试运行现有的流星项目时收到错误消息。

$meteor

=> Started proxy.
=> Started MongoDB.
=> Errors prevented startup:

While building the application:
client/coinmx.html:169: TRIPLE template tag is not allowed in an HTML attribute
...title="Totals:  {{{get...
                        ^

3 个答案:

答案 0 :(得分:3)

在Meteor 0.8中,可以返回一个Javascript对象,该对象直接呈现为HTML属性,而早期版本则必须自行渲染。

旧版本:

<input name={{name}} title={{title}}>

助手:

Template.foo.name = "fooName";
Template.foo.title = "fooTitle";

新版本:

<input {{attributes}}>

助手:

Template.foo.attributes = {
  name: "fooName",
  title: "fooTitle"
};

所有这些都可以是函数,也可以是被动的等等。因为对象直接呈现为属性,所以不需要像以前那样SafeString一些手动呈现的内容。如果需要呈现HTML属性,这是推荐的方法。

有关条件属性如何在此方案下工作,请参阅以下内容:

  

https://github.com/meteor/meteor/wiki/Using-Blaze#conditional-attributes-with-no-value-eg-checked-selected

答案 1 :(得分:1)

错误几乎是解释性的:您不能在HTML属性中使用{{{something}}},而是需要使用{{something}}。取决于something是什么(由于您没有提供代码而未在您的问题中知道),您需要做的就是全部,或者您可以实现类似的目标从帮助者而不仅仅是new Handlebars.SafeString("result")返回"result"的功能。但是,如果你这样做,你需要确保你所返回的东西不会破坏HTML结构。

答案 2 :(得分:1)

上面雨果的答案给了我同样问题所需的缺失部分 - 不再支持0.8中的三个藏匿处。这是一个希望有帮助的例子。

您的模板中可能有{{{resolve}}}的位置,您现在可以:

<template name='thing'>
  <ol>
    {{#each all}}
      {{resolve}}
    {{/each}}
  </ol>
<template>

然后帮助程序代码使用了Spacebars.SafeString,它看起来更适合Blaze:

Template.thing.helpers({
    all: function () {
        return Things.find();
    },

    resolve: function () {
        var result = "<li>";
        for (var i = 0; i < this.arrayOfClassNames.length; ++i)
            result += <'div class='" + this.arrayOfClassNames[i] + "'></div>";
        result += "</li>";
        return new Spacebars.SafeString(result);
    }
});

这里的关键是返回新的Spacebars.SafeString(结果)&#39;包装你的HTML(必须很好地形成)。