获取autoform非集合表单的方法返回值

我想使用meteorautoform为我的非收集forms。 我尝试这种方法,但我想获得方法的返回值,并显示在客户端上。 请指导我如何做到这一点。

这是我的模式( common.js ):

Schema = {}; Schema.echoSchema = new SimpleSchema({ echoText: { type: String, label: "Echo Text", max: 50 } }); 

这是我在客户端( client.js )上的代码:

 Template.showEcho.helpers({ getEchoFormSchema: function() { return Schema.echoSchema; } }); 

这是我在服务器上的代码( server.js ):

 Meteor.methods({ echoMethod: function (doc) { check(doc, Schema.echoSchema); return doc.echoText; }, }); 

这是我的表单模板( showEcho.html ):

  <template name="showEcho"> {{#autoForm schema=getEchoFormSchema id="echoForm" type="method" meteormethod="echoMethod"}} <fieldset> <legend>Echo Form</legend> {{> afQuickField name="echoText"}} <div> <button type="submit" class="btn btn-primary">Submit</button> <button type="reset" class="btn btn-default">Reset</button> </div> </fieldset> {{/autoForm}} <p> // How To Show Echo Text HERE?? Text = ??????????????????? </p> </template> 

Autoform钩子是你的朋友

在这里阅读

添加到您的客户端代码:

 AutoForm.hooks({ 'echoForm': { after: { method: function(error, result) { console.log("after"); if (result) { return Session.set('result', result); } } } } }); 

在你的Template js文件中,创build一个帮助器来返回Session.get'result'

 Template.showEcho.helpers({ text: function() { return Session.get('result') } }); 

模板html文件:

 <template name="showEcho"> {{#autoForm schema=getEchoFormSchema id="echoForm" type="method" meteormethod="echoMethod"}} . . . . {{/autoForm}} <p> {{text}} </p> </template>