2016-11-23 56 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對非反應道具的建議做到了。發現錯誤,是有關聯的。非常感謝,花了很長時間才找到這個。 –

回答