【发布时间】:2014-06-03 00:13:48
【问题描述】:
我正在使用带有 Blaze 的 Meteor 0.8,我想将事件动态附加到使用模板的 UI.toHTML 生成的 HTML 内容。我正在寻找的功能是 Blaze 中 Spark.attachEvents 的替代品。
到目前为止,我所做的是创建了以下模板,以便像小部件/组件一样使用。
<template name="postLinks">
<div id="link-popover-wrapper" >
<ul class="link-popover">
{{#each linkOptions}}
<li><a tabindex="-1" class="link-action" id="link-{{value}}" href="#">{{label}}</a>
</li>
{{/each}}
</ul>
</div>
</template>
并且该模板用于myPostItem模板的Helper中。
Template.myPostItem.events({
'click .post-item-link-picker': function (evt, tmpl) {
var tempData = {linkOptions:[{label:'Favorite', value : 'favorite'}, ...]};
// Get the HTML content of the template passing data
var linkContent = UI.toHTML(Template['postLinks'].extend({data: function () { return tempData; }}));
// Attach events to the linkContent like in Spark
/*Spark.attachEvents({
'click link-action': function (e, tmpl) {
alert("Component item click");
}
}, linkContent);*/
// Popover the content using Bootstrap popover function
}
});
所以我的要求是将事件附加到动态生成的 HTML 内容中。在上面代码中提到的以下行之后的 linkContent 中,如 Spark.attachEvents。
var linkContent = UI.toHTML(Template['postLinks'].extend({data: function () { return tempData; }}));
希望有人可以帮助找到在 Meteor 0.8 中使用 Blaze 执行此操作的方法。
【问题讨论】:
标签: meteor meteor-blaze