[英]Meteor reactive collection data
我得到帮助者的预订/数据:
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}}
如何使这些数据具有反应性? 我的意思是,当我在bookingName
中更改例如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;
},
}
您需要从服务器发布预订信息,然后从客户端进行预订。 它可能看起来像这样:
// server/publications.js
Meteor.publish('bookingData', function() {
return Bookings.find({userId: this.userId});
});
// client/template.js
Template.dashboard.helpers({
userBookings() {
return Bookings.find({userId: Meteor.userId()});
}
});
Template.dashboard.onCreated(function() {
this.subscribe('bookingData');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.