0
我有这个问题,即rendered
函数被调用,而元素还没有在DOM中。让我描述一下我的情况。模板看起来是这样的:流星:wainOn(铁路线)不工作
<template name="barfoo">
<ol>
{{#each bars}}
<li item>{{title}}</li>
{{/each}}
</ol>
</template>
而下面的javascript代码
Template.barfoo.bars = function() {
return Bars.find({});
};
Tempalate.barfoo.rendered = function() {
var bars = Bars.find({}).fetch();
var list = $('[items]');
};
当rendered
函数被调用bars == list == []
。 因此,要解决这个问题,我实现Iron routes这样
Bars = new Meteor.Collection('bars');
// Routes
Router.configure({
layout: 'layout',
loadingTemplate: 'loading',
notFoundTemplate: 'notFound'
});
Router.map(function() {
this.route('/', {
controller: 'BarsController',
});
});
if (Meteor.isClient) {
App = {
subs: {
bars: Meteor.subscribe('bars'),
...
}
};
MainController = RouteController.extend({
template: 'barfoo',
before: function() { ... },
waitOn: function() {
return [App.subs.bars];
}
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
Meteor.publish('bars', function() {
return Bars.find({});
});
}
所有的基础知识,但是当我现在就去为localhost:3000我仍然在rendered
功能空列表获取。任何建议有什么问题在这里?
我需要深入了解这一点,但你是对的。我无法复制 - 直接通过'onBeforeAction'进入我的项目(遇到lookupHook错误或某事),但我确实添加了[action](https://github.com/EventedMind/iron-router)方法我的控制器做到了!日Thnx! –