2016-11-23 91 views
1

我在流星的MongoDB中遇到了一些麻烦。基本上,我想更新嵌套在数组中的对象的属性。整个对象的结构如下:流星 - 蒙戈不会更新,在阵列中的对象

product { 
_id: 
some other properties 
template: { 
    some other properties 
    additionalFields: [ 
     { _id: 
     content: **update this** 
     } 
    ] 
} 
} 

我写了下面的流星方法:

'products.update.field.content': function(product, field, update) { 
    return Products.update(
     {_id: product._id, 'template.additionalFields._id': field._id}, 
     {$set: {'template.additionalFields.$.content': update }}); 
} 

,并在呼叫我用

onInputChange(event) { 
    const { product, field } = this.props; 
    Meteor.call('products.update.field.content', product, field, event.target.value); 
} 

如果我把一个回调方法(error, update) => console.log(error, update)在我的方法调用中我收到(undefined,1)。然而,当我console.log产品对象内容没有改变。

有人可以帮忙吗? 感谢

+1

应该工作,也许对象没有足够的时间更新或将其映射到您的道具的查询不是被动的。 – MasterAM

+0

是的,@MasterAM对非反应道具的建议做到了。发现错误,是有关联的。非常感谢,花了很长时间才找到这个。 –

回答