0
我建立一個流星應用程序,並在一個路由我添加多個數據背景下,像這樣 -多個數據上下文 - 流星
this.route('orgPage', {
path: '/org/:title',
data: {
orgs: function() {Orgs.findOne(this.params._id)},
projects: function() {Meteor.subscribe('projects', this.params._id)}
}
唯一的問題是,當我嘗試訪問該數據在我的模板js文件中,我無法訪問_id或orgs的任何屬性。
我試過幾種方法,但總是返回undefined。如果我使用單個數據上下文,它可以很好地工作。這裏是功能不正常 -
Template.orgPage.events({
'click #newProject': function(e) {
$('#npModal').modal();
},
'submit #npModal form': function(e, template) {
e.preventDefault();
if(!$(e.target).find('[name=newTitle]').val()) {
var projectTitle = 'Untitled'
} else {
var projectTitle = $(e.target).find('[name=newTitle]').val()
}
var theid = this._id;
var newProject = {
title: projectTitle,
organization: theid
}
Meteor.call('project', newProject, function(error, id) {
if (error)
return alert(error.reason);
$('#npModal').modal('hide');
$('#npModal').on('hidden.bs.modal', function (e) {
Router.go('newFields', {});
})
});
});
任何有什麼想法?謝謝!!