【问题标题】:How to render HTML of Meteor Session variable?如何渲染 Meteor Session 变量的 HTML?
【发布时间】:2012-05-28 09:21:27
【问题描述】:

进一步my previous post about obtaining data from objects on the server using Meteor.call 我想知道一旦从服务器接收到类似的对象数据,这些相同的数据如何呈现 HTML。这是一个简单的例子:

/server/svr.js
Meteor.methods({
  test: function(text) {
    var result = {};
    result.foo = "<em>" + text + "</em>";
    result.bar = text;
    return result;
  }
});

/client/del.js
Meteor.call('test', "Hello World - May 2012", function(err, data) {
if (err)
  console.log(err);

  Session.set('q', data);
});

Template.hello.greeting = function() {
  return Session.get('q').foo;
};

当我在浏览器窗口中看到的标准流星应用程序中运行此代码时:

Hello World!
<em>Hello World - May 2012</em>

理想情况下,我希望包含 html 代码的会话变量能够渲染传递给它的内容(在上面的简单示例中 - 在输出到浏览器时使第二行变为斜体)。我该怎么做呢?

提前感谢您的帮助!

【问题讨论】:

  • 让服务器返回标记很奇怪。为什么hello 模板中没有&lt;em&gt; 标签?

标签: html meteor


【解决方案1】:

使用{{{greeting}}} 而不是{{greeting}} 以确保它不会被转义。

【讨论】:

    猜你喜欢
    • 2016-01-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-27
    • 2014-09-27
    • 2015-05-09
    • 2019-07-24
    • 2019-08-27
    • 2015-12-21
    相关资源
    最近更新 更多