【发布时间】:2016-04-12 09:44:21
【问题描述】:
我通过助手获取预订/数据:
Template.dashboard.helpers ({
getUserBookings: function() {
_deps.depend();
var user = Meteor.user();
getBookingsClient(user.emails[0]['address'], function(err, res){
if ( err ) { console.log("Booking get error.");
} else {
console.log("Booking get correct.");
Session.set('bookingResponse', res);
}
});
return Session.get('bookingResponse') || "";
}
在我的模板中:
{{#if getUserBookings}}
{{#each getUserBookings}}
{{bookingName}}
{{/each}}
{{/if}}
如何使这些数据具有反应性?
我的意思是当我在我的 mongoDB 中更改 bookingName 时,它会立即在网站上更改它?
更新:
if(Meteor.isClient) {
getBookingsClient = function (email, callback) {
Meteor.call('getBookings', email, callback);
};
}
if(Meteor.isServer) {
getBookings: function (email) {
check(email, String);
var bookings = Bookings.find({'clientDetails.email': email}).fetch();
return bookings;
},
}
【问题讨论】:
-
能否包含 getBookingsClient() 的代码?
-
无关紧要。这是一个实施错误。方法调用不是响应式的(尽管它们可以放置在自动运行块中)。这种情况需要订阅。
-
@BrettMcLain 更新
-
你的方法根本不正确。我建议做官方Meteor Tutorial 的基本用法示例。
-
常规方法调用还是meteor方法调用?由于他的语法,它看起来像是对我的常规方法调用;很明显,原来是一个meteor方法调用。
标签: javascript mongodb meteor meteor-blaze