我正在使用 Meteor 1.6 ,并尝试使用下面的aldeed的quickForm更新集合。
收藏:
import { Mongo } from 'meteor/mongo';
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
export const Settings = new Mongo.Collection('Settings');
SettingsSchema = new SimpleSchema({
"userId": {
type: String,
label: "User ID",
},
"speed": {
type: Number,
label: "Speed",
},
"fuelLevel": {
type: Number,
label: "Fuel Level",
},
"fuelCapacity": {
type: Number,
label: "Fuel Capacity",
},
"temperature": {
type: Number,
label: "Temperature",
},
}, { tracker: Tracker });
Settings.attachSchema(SettingsSchema);
UI.js
import './ManageAlerts.html';
import '../../../components/common/staggering/Staggering';
import { Settings } from '/imports/api/users/settings';
window.Settings = Settings;
Template.ManageAlerts.onCreated(function () {
console.log('Landed on page');
this.subscribe('Settings.Individual');
});
Template.ManageAlerts.helpers({
settings() {
return Settings.find({ userId: Meteor.userId() });
},
Settings() {
return Settings;
}
});
UI.html
<template name="ManageAlerts">
<div class="content">
<div class="row">
{{#each settings}} {{> quickForm collection="Settings" id=_id type="update" doc=this}} {{/each}}
</div>
</div>
</template>
错误:
Exception in template helper: TypeError: Cannot read property 'singleType' of undefined
at SimpleSchema.getQuickTypeForKey (http://localhost:3000/packages/modules.js?hash=205c3cd7764df56011db912e818af184cf564869:30655:40)
at Object.getInputType (http://localhost:3000/packages/aldeed_autoform.js?hash=51e89e15ba8f6061bd5bdff815c619d09399c305:2469:29)
at Object.afFieldInputContext (http://localhost:3000/packages/aldeed_autoform.js?hash=51e89e15ba8f6061bd5bdff815c619d09399c305:6383:30)
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3051:16
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:1715:16
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3103:66
at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3744:12)
at http://localhost:3000/packages/blaze.js?hash=a1ff2d6d5ecd59ee11e2ba260b8650a9d1140f59:3102:27
at Object.Spacebars.call (http://localhost:3000/packages/spacebars.js?hash=547cf8e466d1d52603d19bd5f48fb5df184fd237:172:18)
at http://localhost:3000/packages/aldeed_autoform.js?hash=51e89e15ba8f6061bd5bdff815c619d09399c305:6317:23
任何帮助将不胜感激。
答案 0 :(得分:0)
未定义您的收藏集时,会发生此错误。
一种可能的解决方法是像这样使集合成为全局的:
#unignore gz files
!*.gz
否则,您可以更改模板将集合返回表单的方式:
global.Settings = Settings; // try this instead of window
现在,因为您已经定义了此帮助器,所以它使用了一个帮助器来显式接收该集合,而不是查看全局范围:
{{> quickForm collection=Settings id=_id type="update" doc=this}}
如果这仍然不起作用,还请检查给定路径是否正确导入了集合(例如,尝试不以Settings() {
return Settings;
}
开头,而是相对于当前目录)。