【发布时间】:2014-02-18 05:01:40
【问题描述】:
我的 Meteor 模板没有获取它的数据。它是一个路由的,它的所有车把字段都没有显示任何内容。
这是我的路由器的相关部分。
this.route('admin', {
before: function() { if (!isAdmin()) Router.go('home'); },
data: function() { return Meteor.users.find(); },
waitOn: function() { return Meteor.subscribe('adminAllUsers'); }
});
this.route('adminUser', {
path: '/admin/:_id',
before: function() { if (!isAdmin()) Router.go('home'); },
// this is a potential problem area.
data: function() { return Meteor.users.find(this.params._id); },
waitOn: function() { return Meteor.subscribe('adminUser', this.params._id); }
});
我的出版物似乎在做他们的工作,因为当我在控制台中执行Meteor.users.find().fetch() 之类的操作时,带有正确字段的正确对象都会弹出。如果您想查看相关出版物,请询问。
我的模板:
<template name="admin">
{{#each this}}
// Here, since I'm using 'pathFor', it passes the id automatically. I'm not sure if that means I don't have to use the 'data' hook in the router.
<a href="{{pathFor 'adminUser'}}">{{customer.firstname}} {{customer.lastname}}</a>: ${{customer.balance}}
{{/each}}
</template>
<template name="adminUser">
Admin user
{{testing}}
// None of these show up, not even the id.
{{_id}}
{{customer.firstname}}
{{#each emails}}
{{address}}
{{/each}}
{{#with customer}}
{{firstname}} {{lastname}}
{{/with}}
</template>
而且我的 javascript 中有这个助手:
Template.adminUser.testing = function() {
console.log(this);
}
当这个助手记录它的日志时,它会打印:
Object {collection: LocalCollection, selector_id: "veW6jvfSM5Jc46Wbj", selector_f: function, sort_f: undefined, skip: undefined…}
当我深入研究它那里有一切,selector_id 是正确的路线。
为什么什么都没有显示?
【问题讨论】:
标签: meteor handlebars.js