如何整合Backgrid和Meteor?我正在使用流星包productiveme:meteor-backgrid
,它使用最新的Backgrid版本,但没有在流星中使用的文档。我的两个主要问题是:
问题# 1
如何将Meteor/MongoDB集合或游标转换为Backbone集合来填充表?(发布/订阅功能正确,数据可以在Backgrid外成功访问)
问题#2
由于Backgrid是通过javascript启动的,而不是模板的情况下,我这样做在最"流星"的方式?
Template.customers.onRendered(function() {
var project_id = Session.get('current_project')._id;
var allCustomers = Customers.find({'project': project_id}).fetch();
var columns = [
{
name: 'name',
label: 'Name',
cell: 'string'
},
];
var grid = new Backgrid.Grid({
columns: columns,
collection: allCustomers,
});
$("#table-container").append(grid.render().el);
});
下面是来自控制台的错误:
TypeError: obj[implementation] is not a function
at _.each.Events.(anonymous function) [as listenTo] (http://mb-air.local:3000/packages/productiveme_backgrid.js?7cf0e8ad9ae9ed918329b72c89c983e50097c6f6:282:26)
at Backgrid.Body.Backbone.View.extend.initialize (http://mb-air.local:3000/packages/productiveme_backgrid.js?7cf0e8ad9ae9ed918329b72c89c983e50097c6f6:4014:10)
嗯,我能够通过设置一些虚拟骨干模型和集合来解决问题#1,如下所示:
var allCustomers = Customers.find({'project': project_id}).fetch();
var MyModel = Backbone.Model.extend({
defaults: {
id: null,
name: null,
}
});
var MyCollection = Backbone.Collection.extend({
model: MyModel,
initialize: function(models, options) { }
});
var myCollections = new MyCollection(allCustomers);
var columns = [
{
name: 'name',
label: 'Name',
cell: 'string',
editable: false,
},
];
var grid = new Backgrid.Grid({
columns: columns,
collection: myCollections,
});
$("#table-container").append(grid.render().el);
BUT表不是响应的。我还在学习Meteor,所以如果有人能给我一些建议,告诉我哪里做错了,那就太棒了。