2015-04-02 48 views
0

我使用aldeed:autoform來渲染表單並通過Meteor.method()運行結果。我的表單看起來如下:用流星方法提交url參數與表格

SelectPlanTemplates = new SimpleSchema({ 
    templates: { 
    type: [String], 
    autoform: { 
     options: function() { 
     return PlanTemplates.find().map(function(doc) { 
      return { label: doc.title, value: doc._id }; 
     }); 
     }, 
     noselect: true 
    } 
    }, 
    userId: { 
    type: String, 
    allowedValues: function() { 
     return Meteor.users.find().map(function(doc) { 
     return doc._id; 
     }); 
    }, 
    autoform: { 
     omit: true 
    } 
    } 
}); 

在我的模板上,我只做了以下操作。

+ionContent 
    +quickForm(schema="SelectPlanTemplates" id="SelectPlanTemplatesForm" type="method" meteormethod="createPlanFromTemplates") 

我的網址的結構類似/plan/from_templates/{:userId}。我試圖創建一個鉤子來提交它之前添加用戶ID。

AutoForm.hooks({ 
    SelectPlanTemplatesForm: { 
    before: { 
     method: function(doc) { 
     doc.userId = Router.current().params.userId; 
     return doc; 
     } 
    } 
    } 
}); 

但是,它似乎從來沒有得到這個鉤子。

我將如何採取路線參數,並將其與我的表單傳遞給自動形式的流星方法?

回答

0

我想我想出了一點奇怪的做法。

在路由器:

this.route('selectPlans', { 
    waitOn: function() { 
    return Meteor.subscribe('plan_templates'); 
    }, 
    path: '/select/plan_templates/:_id', 
    template: 'selectTemplates', 
    data: function() { 
    return new selectPlanTemplates({ userId: this.params._id }); 
    } 
}); 

然後我說doc=this到我的模板