【发布时间】:2018-07-03 04:53:10
【问题描述】:
我已将我的归档和 shema 定义为:
storageArticles:
{
type: Array,
autoValue: function() {
return [];
},
label: 'Articless added to storage.',
},
'storageArticles.$': {
type: String
}
当我尝试使用(在我的服务器端方法中)更新此字段时:
Storages.update(storageId , {$set: { "storageArticles" : articleId }});
一切正常,但数据没有添加到数组中。
你能给我一些指导来解决这个问题吗?
编辑
编辑添加了有关此问题的更多详细信息,也许这是我的错误。
'articles.articleAddToStorage': function articleAddToStorage(storageId,articleId) {
check(storageId, String);
check(articleId, String);
try {
Articles.update(articleId, { $set: {articleAssignedToStorage:true}});
Storages.update(storageId , {$addToSet: { "storageArticles" : articleId }});
} catch (exception) {
handleMethodException(exception);
}
}
handleAddToStorage()
{
const articleId = this.props.articleId;
const storageId = this.state.storageId;
const history = this.props.history;
if(storageId!="")
{
Meteor.call('articles.articleAddToStorage', storageId,articleId, (error) => {
if (error) {
Bert.alert(error.reason, 'danger');
} else {
Bert.alert("Article assigned to storage", 'success');
}
});
}
else {
Bert.alert("Plese select storage", 'warning');
}
}
【问题讨论】:
标签: meteor simple-schema meteor-collection2