给定一个带有body
属性的post
模型,有没有办法让ember在body
属性中动态呈现{{link-to}}
?
示例:
// The model
post = {
body: `
{{#link-to "posts.index"}}
<h1>The "{{#link-to}}" is rendered literally!</h1>
{{/link-to}}`
}
// The .hbs file
<div class="container">
{{postBody post.body}}
</div>
// Helper function to avoid escaping the HTML
export function postBody(postBody) {
return Ember.String.htmlSafe(postBody);
}
export default Ember.Helper.helper(postBody);
我能想到的唯一一件事就是输入一个静态链接,这会导致整个页面重新加载。
发布于 2015-12-21 21:48:33
我认为您正在寻找的是compile
函数。有关详细信息,请参阅here。你可以这样称呼它:
Ember.Handlebars.compile(this.get('post.body');
https://stackoverflow.com/questions/34396606
复制相似问题