我需要重置一个弹出表单,其中的值全部由 session 变量填充:
Template.customerinfo.name = -> Session.get('activeCustomer').name
现在我手动做:
Template.customerinfo.events
'click #cancelButton': ->
Client.getById('inputName').val(Session.get('activeCustomer').name)
Meteor.render
会更加困惑,因为我必须提取当前的表单/模板,使用 Meteor.render 创建一个新的表单/模板,然后将其插入到 DOM 中。
有没有办法告诉 meteor 重置表单或模板并从它们的源中提取值?
最佳答案
在您的 Handlebars 模板中,即在您执行 Meteor.call() 或集合插入/更新之后,放置此 jQuery 调用。它返回 DOM 中的第一个表单,然后调用 DOM reset()。
$('.add-post-form')[0].reset();
在您的 HTML 中:
<form class="form-horizontal add-post-form" role="form">
// Your form HTML.
</form>
关于meteor - 如何在 Meteor 中重置表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20760368/