【发布时间】:2015-05-02 14:24:38
【问题描述】:
我在 Meteor 中使用 Simple Schema、collection hooks 和 Autoform 包,并且我试图在 after update 集合 hook 中更新我的模式中的 Embedded 对象。我觉得我可能会做一些愚蠢的事情,但就是无法解决这个问题。我在保存时得到了例外:Exception while invoking method '/providers/update' Error: 0 must be an integer
我的架构:
Schemas.Providers = new SimpleSchema({
email: {
type: String,
label: 'Email Address',
autoValue: function() {
if (this.isInsert || this.isUpdate) {
return Meteor.user().emails[0].address;
}
},
autoform: {
afFieldInput: {
type: 'email'
}
}
},
officelocation: {
type: String,
label: 'Location of Office',
optional:true
},
location: {
type: [LocationSchema],
optional:true
}});
有效的收集钩子:
Providers.after.update(function (userId, doc) {
var oldDoc = this.previous;
Providers.direct.update({_id: doc._id},{$set: {location:{
type:'Point',
coordinates:[0,0]
}}});
});
集合钩子不起作用。理想情况下,我不应该在集合更新后更新,但想确保它有效:
Providers.after.update(function (userId, doc) {
var oldDoc = this.previous;
var array=[];
var iArray=doc.officelocation.split(",");
array.push(Number(iArray[1]));
array.push(Number(iArray[0]))
Providers.direct.update({_id: doc._id},{$set: {location:[{
type:'Point',
coordinates:array
}]}});
});
【问题讨论】:
标签: meteor meteor-autoform meteor-collection2