流星快速表格方法没有解雇

时间:2015-12-07 21:24:33

标签: meteor meteor-autoform

我有一个流星形式,我不希望用户能够修改id,所以我省略了该字段。但是我把它添加回来才能继续更新。当我提交表单时,它会卡住,服务器永远不会被调用..

任何帮助表示感谢,谢谢!

donators.html:

<template name="dInfo">
  {{> dMove}}
  {{#if getDoc}}
    <label for="num">Numéro</label>
    <input type="text" id="num" class="form-control" placeholder="ID" value="{{getDoc._id}}" readonly>
    {{> quickForm schema=nwsc omitFields="_id" id="dUpt" doc=getDoc type="method" meteormethod="sayHi" buttonContent="Soumettre" buttonClasses="btn btn-lg btn-primary btn-block"}}
    <button type="button" class="btn btn-lg btn-primary btn-warning btn-block btn-del">Supprimer</button>
  {{/if}}
</template>

客户方:

AutoForm.hooks({
  dUpt: {
    before: {
      method: function(doc) {
        doc._id = donators.find().fetch()[cursor.get()]._id;
      }
    },
    onError: function(i, e) {
      console.log(i);
      console.log(e);
    }
  }
});

服务器端:

Meteor.methods({
  sayHi: function(ins) {console.log(ins);},
  updateDonator: function(ins) {
    if(Meteor.userId() === null)
      return;
    if(ins._id === undefined)
      return;
    if(check(ins, dSchema) === false)
      return;

    dSchema.clean(ins);
    ins.closed = false;
    donators.update({_id: ins._id}, {$set: ins});
    logs.insert({user: Meteor.userId(), email: Meteor.user().username, table: 'Donators', action:'Update', item: ins._id, date: new Date()});
  }
});

sayHi从未记录任何内容,我认为这种情况从未被调用,并且不会发生任何错误。

谢谢!

1 个答案:

答案 0 :(得分:0)

根据AutoForm documentation about callback hooks,在之前的事件中,您可以修改文档并通过以下任一方式返回:

// Then return it or pass it to this.result()
return doc; (synchronous)
return false; (synchronous, cancel)
this.result(doc); (asynchronous)
this.result(false); (asynchronous, cancel)

您的代码未返回修改后的文档。将return doc;添加到之前 - &gt;方法:

AutoForm.hooks({
  dUpt: {
    before: {
      method: function(doc) {
        doc._id = donators.find().fetch()[cursor.get()]._id;
        return doc;  // Add this line
      }
    },
    onError: function(i, e) {
      console.log(i);
      console.log(e);
    }
  }
});

如果AutoForm没有获得doc对象,它将取消操作。