代码之家  ›  专栏  ›  技术社区  ›  Ankur Soni

模板帮助程序中出现异常:TypeError:无法读取未定义的属性“singleType”

  •  0
  • Ankur Soni  · 技术社区  · 8 年前

    我正在使用

    收藏

    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);
    

    用户界面.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;
        }
    });
    

    用户界面.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
    

    任何帮助都将不胜感激。

    1 回复  |  直到 8 年前
        1
  •  0
  •   Jankapunkt    8 年前

    未定义集合时会发生此错误。

    一个可能的解决方法是使集合全局化,如下所示:

    global.Settings = Settings; // try this instead of window
    

    否则,您只需更改模板将集合返回表单的方式:

    {{> quickForm collection=Settings id=_id type="update" doc=this}}
    

    Settings() {
        return Settings;
    }
    

    如果这仍然不起作用,请同时检查集合是否由给定路径正确导入(例如,尝试不以开头) /imports 但这是当前目录)。