【问题标题】:how to insert a string containing a link with a helper in meteor blaze如何在流星火焰中插入包含带有助手的链接的字符串
【发布时间】:2014-07-14 23:34:51
【问题描述】:

我想在流星火焰中插入一个字符串,其中包含一个带有帮助器的链接(或者有更好的选择吗?)。

到目前为止,blaze 只是将链接作为带有 '' 标签的普通文本返回。

有没有人对此有好的解决方案或解决方法?

【问题讨论】:

    标签: meteor meteor-blaze


    【解决方案1】:

    这里有一个简单的例子让你开始:

    <template name="parent">
      {{> linkTemplate linkData}}
      {{#each links}}
        {{> linkTemplate}}
      {{/each}}
    </template>
    
    <template name="linkTemplate">
      <a href="{{url}}">{{title}}</a>
    </template>
    
    Links=new Meteor.Collection(null);
    Links.insert({
      url:"https://www.google.com",
      title:"Google"
    });
    
    Template.parent.helpers({
      linkData:function(){
        return {
          url:"https://www.google.com",
          title:"Google"
        };
      },
      links:function(){
        return Links.find();
      }
    });
    

    如果要在恰好包含链接的模板中呈现字符串,则必须提供 HTML 字符串,如

    var string="A link to <a href="https://www.google.com">Google</a>.";
    

    然后您可以使用三方括号语法 {{{helperReturningHTMLString}}},它会按预期工作,但我认为这不是一个好习惯,除非您使用所见即所得的编辑器。

    【讨论】:

    • 也许我的例子不够好,但没关系,三方括号是解决方案;)谢谢!抱歉我还不能投票:'(
    猜你喜欢
    • 2014-11-26
    • 2016-05-18
    • 2014-07-14
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-03
    相关资源
    最近更新 更多