【问题标题】:Update form in meteor using autoform使用 autoform 更新流星中的表单
【发布时间】:2016-07-06 21:00:17
【问题描述】:

我有一个处理表单默认值的集合。我需要构建一个 UI 来自行更新默认值,而不是通过支持 mongo 的强制更新。

我使用了 aldeed 的 update-each 功能。正在从数据库中获取数据并显示在表中。但是,当我尝试通过在文本框中输入新值来更新时,它不会持续存在。事实上,它一直在抛出这个我不知道的错误。

Exception in template helper: TypeError: Cannot read property 'namedContext' of undefined
    at Object.autoFormFieldIsInvalid

作为示例,这是我正在使用的:

Mongo 收藏:

meteor:PRIMARY> db.testCollection.find()
{ "_id" : ObjectId("577ccd87f57f43d790c3ec49"), "schemaName" : "test_schema", "label" : "test_lable", "value" : "test_value" }

架构:

test_schema = new SimpleSchema({
    "schemaName": {
        type: String,
    },
    "label": {
        type: String,
    },
    "value": {
        type: String,
    }
});

testCollection.attachSchema(test_schema);

模板:

<template name = "testTemplate">

<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <td style="width: 85px">Schema Name</td>
        <td style="width: 85px">Label</td>
      <td>Default Value</td>
      <td style="width: 250px">New Default Value</td>
    </tr>
  </thead>
  <tbody>
    {{#each items}}
      <tr>
        <td>{{this.schemaName}}</td>
        <td>{{this.label}}</td>
        <td>{{this.value}}</td>
        <td>
        {{#autoForm id=updateDefaiultsID type="update" collection=testCollection doc=this autosave=true}}
          {{> afFormGroup name="value" label=false}}
        {{/autoForm}}
        </td>
      </tr>
    {{/each}}
  </tbody>
</table>


</template>

助手

import { Template } from 'meteor/templating';
import '../templates/testTemplate.html';


if (Meteor.isServer) {

  Meteor.publish(null, function () {
    return testCollection.find();
  });

  testCollection.allow({
    update: function () {
      return true;
    }
  });
}

else if (Meteor.isClient) {

  Template["testTemplate"].helpers({
    items: function () {
      return testCollection.find({}, {sort: {name: 1}});
    },
    updateDefaiultsID: function () {
      return "testTemplate" + this._id;
    }
  });
}

【问题讨论】:

    标签: mongodb meteor meteor-autoform


    【解决方案1】:

    改变这个 来自

    <td>{{this.schemaName}}</td>
    

    <td>{{this.schema_name}}</td>
    

    【讨论】:

    • 谢谢约翰,但是,我不明白这会有什么帮助。 schemaName 是在 mongodb 级别以及架构级别定义的标签。我的看法是,如果我要进行您提到的更改,它实际上不会填充架构名称列下的任何内容。请您对这方面进行更多说明吗?
    • 你必须遵循一些 json 格式的数据结构标准,返回 .... @blueren
    猜你喜欢
    • 2017-05-21
    • 2017-04-22
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 2016-03-23
    • 2016-04-17
    • 2013-11-07
    相关资源
    最近更新 更多