【问题标题】:TypeError: Cannot read property 'slice' of nullTypeError:无法读取 null 的属性“切片”
【发布时间】:2015-08-31 17:02:35
【问题描述】:

我在我的项目中使用 autoform,打开表单时出现此错误 不确定这是否是因为任何版本或依赖关系,我的自动表单无法正常工作,我收到此错误,我有屏幕截图和架构代码,下面的表单代码,

模板

<template name="assesmentNew">
  {{#ionModal customTemplate=true}}
    {{# autoForm collection="Assesments" id="assesments-new-form" type="insert"}}
      <div class="bar bar-header bar-stable">
        <button data-dismiss="modal" type="button" class="button button-clear">Cancel</button>
        <h2 class="title">New Assesment</h2>
        <button type="submit" class="button button-positive button-clear">Save</button>
      </div>
      <div class="content has-header overflow-scroll">
        {{> afQuickField name="name" }}
        {{> afQuickField name="email"}}
        {{> afQuickField name="category"}}
        {{> afQuickField name="location"}}
      </div>
    {{/autoForm}}
  {{/ionModal}}
</template>

收藏

Assesments = new Mongo.Collection('assesments');
Assesments.before.insert(function (userId, doc) {
  doc.createdAt = new Date();
});


Assesments.attachSchema(new SimpleSchema({
  name: {
   type: String,
    label: 'First Name',
    autoform: {
      'label-type': 'floating',
      placeholder: 'First Name'
    }
  },
  email: {
    type: String,
    label: 'Email',
    autoform: {
      'label-type': 'floating',
      placeholder: 'Email'
  }
  },
  category: {
    type: String,
      label: 'Category',
    optional: true,
    autoform: {
      options: [
        {value: 'General', label: 'General'},
        {value: 'Reported', label: 'Reported'},
        {value: 'Follow Up', label: 'Follow Up'}
      ],
      type: 'select-radio'
    }
  },
 assesmentDate: {
    type: Date,
    label: 'Assesment Date',
    optional: true
  },
  location: {
    type: String,
      label: 'Location',
      autoform: {
      'label-type': 'floating',
      placeholder: 'Location'
    },
    max: 200
  },
 createdBy: {
    type: String,
    autoValue: function() {
    return this.userId
  }
}
  }
    ));

if (Meteor.isServer) {
  Assesments.allow({ 
    insert: function (userId, doc) {
      return true;
    },
    update: function (userId, doc, fieldNames, modifier) {
      return true;
    },
    remove: function (userId, doc) {
      return true;
    }
  });
}

【问题讨论】:

    标签: meteor meteor-autoform meteoric


    【解决方案1】:

    这是新版本 autoform 的 autoform-ionic 新补丁的问题。

    显然有些标签被跳过,有些则没有(见here)。为了解决这个问题并在您的输入类型不存在时避免此错误(例如,type = number),所有由 autoform 呈现的架构字段都必须定义一个标签类型选项:

    ...
    autoform: {
       'label-type': 'placeholder',
       placeholder: 'Linha'
    }
    

    【讨论】:

    • 谢谢,它有效,@Rafael Quintanilha,但由于某种原因插入没有发生。
    • 如果我没有使用 simpleschema 并且也有这个错误怎么办?我虽然使用 Meteoric..
    • 对不起,我是新人,我们到底把这个对象放在哪里?
    猜你喜欢
    • 2017-03-11
    • 2020-01-29
    • 1970-01-01
    • 2022-01-12
    • 2021-12-04
    • 2021-12-17
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多