【问题标题】:Define autoform hook for forms in for each in Meteor为 Meteor 中的每个表单定义 autoform 钩子
【发布时间】:2015-10-06 00:46:55
【问题描述】:
我在 Meteor 中有一个 for each 循环,我正在使用 autoform 更新每个项目(就像在 http://autoform.meteor.com/update-each 中描述的一样)。
我的问题是我通常通过带有
的钩子创建通知
AutoForm.hooks({
myFormId: {
onSuccess: function(formType, result) {
Notifications.success('Title', 'Text.');
}
}
});
但由于我所有的表单都有唯一的 ID,我不能使用它。如何创建一个匹配模板中所有表单或名称匹配正则表达式“unique-id-”的钩子?在哪里 ?是 docId 吗?
【问题讨论】:
标签:
javascript
node.js
meteor
meteor-autoform
【解决方案1】:
这可能不是最佳解决方案,但它确实有效:
Template["updateEach"].helpers({
items: function () {
return Items.find({}, {sort: {name: 1}});
},
makeUniqueID: function () {
return "update-each-" + this._id;
}
});
Template.updateEach.onRendered(function () {
var hooksObject = {
onSuccess: function (formType, result) {
Notifications.success('Title', 'Text.');
}
};
var formIds = Items.find().map(function (item) {
return "update-each-" + item._id;
});
AutoForm.addHooks(formIds, hooksObject);
});