【问题标题】:MeteorJS update AutoForm not loading docMeteorJS 更新 AutoForm 不加载文档
【发布时间】:2015-12-20 07:46:55
【问题描述】:

我有一个带有更新 Autoform 的模板:

<template name = "editLocationPage">
    <div class="flow-text">
      {{#if Template.subscriptionsReady}}
      <div>
      <br>
      {{#autoForm collection="Locations" doc=currentDoc id="editLocationPage" type="update"}}
         <fieldset>
           {{testDoc}}
           <legend>Edit Location / Asset</legend>
           {{> afQuickField name='id'}}
           {{> afQuickField name='text'}}
           {{> afQuickField name='description' rows=3}}
           {{> afQuickField name='type'}}
           {{> afQuickField name='parent'}}
         </fieldset>
         <button type="submit" class="btn waves-effect waves-light">Submit</button>
         <button type="reset" class="btn waves-effect waves-light red">Reset</button>
       {{/autoForm}}
     </div>
     {{/if}}
    </div>
</template>

一些帮助订阅并将文档传递给模板:

Template.editLocationPage.onCreated(function() {
  var self = this;
   self.autorun(function() {
     self.subscribe('singleLocation', Session.get("idTreeView").toString());
   });
});

Template.editLocationPage.helpers({
  currentDoc: function() {
    return Locations.find({"id":Session.get("idTreeView").toString()}).fetch()[0];
  }
});

架构:

// Data subset subscribed to on client
Meteor.publish('locations', function() {
  return Locations.find({}, {fields: {
    text: true,
    id: true,
    type:true,
    parent:true
  }});
});

Meteor.publish('singleLocation', function(locationId) {
  return Locations.find({id:locationId});
});

文档没问题(findOne 返回一个有效的文档),但表单不起作用。有什么想法吗?

【问题讨论】:

  • 控制台有错误吗?
  • debug.js:41 模板帮助程序中的异常:TypeError:无法在 bindDataContext (localhost:3000/packages/…) 处读取 Object.afFieldInputContext (localhost:3000/packages/…) 处未定义的属性“标签”...... ......其次是例外页面
  • 也尝试通过这个而不是运气: Locations.find({"id":Session.get("idTreeView").toString()}).fetch()[0]

标签: meteor


【解决方案1】:

我刚刚发现了问题。我需要添加架构:

{{#autoForm schema=locationFormSchema id="editLocationPage" type="update" collection=Locations doc=currentDoc}}

有一个助手:

Template.editLocationPage.helpers({
  currentDoc: function() {
    return Locations.findOne({"id":Session.get("idTreeView").toString()});
  },
  locationFormSchema: function() {
    return Schema.locations;
  }
});

【讨论】:

  • 抱歉错字。更改 Locations 集合定义:{{#autoForm schema=locationFormSchema id="editLocationPage" type="update" collection="Locations" doc=currentDoc}}
猜你喜欢
  • 2015-12-25
  • 1970-01-01
  • 2015-01-18
  • 1970-01-01
  • 2011-04-08
  • 2017-12-20
  • 1970-01-01
  • 2019-12-18
  • 1970-01-01
相关资源
最近更新 更多