我正在尝试从问题数组中删除特定的索引。我遵循了这两篇文章中的示例:
var quiz = {
quizName: "",
createdBy: "",
theme: "",
isPrivate: "",
expiringDate: "",
createdOn: "",
questions:[
{question: "",
index: "",
answers: [
answer: "",
radioCorrect: "",
index: ""
]},{
question: "",
index: "",
answers: [
answer: "",
radioCorrect: "",
index: ""
]}
]
这给了我一个未指定的错误。我已经尝试过类似的变化。
'deleteQuiz': function(quizId, index1){
Quizes.update({_id: quizId},{ $unset : {questions.index1: 1}})
Quizes.update({_id: quizId},{ "$pull" : {"questions": null}}) }
在更新操作中使用之前,请创建更新对象。您可以使用方括号符号来创建它,如下所示:
'deleteQuiz': function(quizId, index1){
var query = {"_id": quizId},
update { "$unset": { } };
update["$unset"]["questions."+index1] = 1;
Quizes.update(query, update)
/* or if using the $pull operator
var query = {"_id": quizId},
update = { "$pull": { } };
update["$pull"]["questions."+index1] = null;
Quizes.update(query, update)
*/
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句