【发布时间】:2015-05-17 21:53:10
【问题描述】:
我有 typeahead 输入类型适用于输入字段。
我希望能够像使用架构中的其他 [Meteor.ObjectID] 类型(或可能的任何数组类型)一样使用它。 {{> afQuickField}} 应该识别数组并将其包装在“afArrayField”模板中,为其提供出色的添加/删除按钮和功能,并返回一个数组。
目前,我只收到输入的一个实例,并在提交时收到一条错误消息,指出该值必须是一个数组。
我正在搜索autoform's 代码库,寻找如何在其他输入类型上实现这一点,但到目前为止还没有运气,因为有很多代码。我只接受一个指向当前执行此操作的代码的指针。
更多信息
我在autoform-api.js 中找到了AutoForm.getInputType 函数。我可能不得不重载它以获得我想要的行为。仍然欢迎更好的替代品!
也试过了
所以我认为诀窍可能是它响应嵌套模式数组。不需要重载,只需将我的 typeahead 字段放入单独的模式中,并将其嵌套在我的主模式中。
myTypeahead = new SimpleSchema({
item:{
type: Meteor.ObjectID,
autoform: {
type: "typeahead"
},
...
}
});
myMainSchema = new SimpleSchema({
itemId:{
type: [myTypeahead]
}
});
这设置了添加/删除字段的能力。不足之处?现在 typeahead 会像发疯一样抛出错误。
Exception in template helper: TypeError: Cannot read property 'lastIndexOf' of undefined
at inflectedLabel (/packages/aldeed_simple-schema.js?8fda161c43c0ba62801a10b0dfcc3eab75c6db88:2125:44)
at SimpleSchema.getDefinition (/packages/aldeed_simple-schema.js?8fda161c43c0ba62801a10b0dfcc3eab75c6db88:2670:30)
at Object.autoFormGetOptionsForField [as _getOptionsForField] (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:2690:12)
at Object.afOptionsFromSchema (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:1519:12)
at bindDataContext (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:16)
at Blaze._wrapCatchingExceptions (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:16)
at Object.Spacebars.call (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:18)
at /client/template.person.js?684475f8f7f0a8f9fe76ecebd81f50a84a03f24d:142:30
at Blaze._TemplateWith.wrappedArgFunc (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2639:14)
at null.<anonymous> (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2445:26)
Exception in template helper: TypeError: undefined is not a function
at /packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:212:34
at /packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:176:29
at _.each._.forEach (/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:164:22)
at Function._.map._.collect (/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:175:5)
at Object.getSelectOptions (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:211:25)
at getInputData (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:1783:37)
at Object.afFieldInputContext (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:6999:17)
at bindDataContext (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:16)
at Blaze._wrapCatchingExceptions (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:16)
at Object.Spacebars.call (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:18)
Exception in template helper: TypeError: Cannot read property 'class' of undefined
at Object.addClass (/packages/aldeed_autoform.js?95e4d3c1e4a248502de2befc9436a32b15999fa3:641:20)
at Object.Template.afTypeahead.helpers.atts (/client/quickForm/autoform-typeahead.js?5037f57aba2aa1b9ec271e4ade183a5d126781e5:43:29)
at bindDataContext (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2727:16)
at Blaze._wrapCatchingExceptions (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1606:16)
at Spacebars.call (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:171:18)
at Spacebars.mustacheImpl (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:108:25)
at Object.Spacebars.attrMustache (/packages/spacebars.js?7f53771c84a2eafac2b561c9796dda0d8af8e7f5:124:39)
at /client/quickForm/template.autoform-typeahead.js?e749e8ff2e104b2c1b5d2ca1f3f7bf538c5790e7:17:22
at Object.Blaze._withCurrentView (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2043:12)
at Blaze._HTMLJSExpander.def.visitAttributes (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1962:21)
Exception from Tracker afterFlush function: Cannot read property 'atts' of undefined
TypeError: Cannot read property 'atts' of undefined
at Template.afTypeahead.rendered (/client/quickForm/autoform-typeahead.js?5037f57aba2aa1b9ec271e4ade183a5d126781e5:74:16)
at null.<anonymous> (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:3008:21)
at /packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1733:14
at Object.Blaze._withCurrentView (/packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:2043:12)
at /packages/blaze.js?efa68f65e67544b5a05509804bf97e2c91ce75eb:1732:15
at Tracker.flush (/packages/tracker.js?517c8fe8ed6408951a30941e64a5383a7174bcfa:448:11)
【问题讨论】:
标签: meteor schema typeahead.js meteor-autoform