问题是你的
home
呈现模板
其嵌套模板。因此,没有任何
.grid-item
元素。
.isotope(...)
使用
Meteor.defer()
或
Meteor.setTimeout()
希望这能给嵌套模板足够的时间来渲染:
Template.home.onRendered(function() {
Meteor.setTimeout(function() {
$('.grid').isotope({
// options
});
}, 250);
补充
另一个选项是嵌套模板从其
onRendered
功能:
Main template
Template.home.onCreated(function() {
this.renderGrid = _.debounce(() => {
$('.grid').isotope({
// options
});
}, 250);
});
Template.home.events({
'ready.griditem .grid'(e, tpl) {
tpl.renderGrid();
}
});
Nested template
:
Template.card.onRendered(function() {
$('.grid').trigger('ready.griditem');
});