我有这段代码,但出于某种原因,我一直在收到colours.undefined
var varray = new Array("WH", "BL");
var fname = "colours",
lname = "size_code_id";
var arr = new Array();
var mquery = {
"$or": []
};
for (var i = 0; i < varray.length; i++); {
var query = {
"$and": []
};
var s1 = fname.concat(".").concat(varray[i]);
var s2 = fname.concat(".").concat(varray[i]).concat(".").concat(lname);
var sub1 = {}, sub2 = {};
sub1[s1] = {
$exists: 1
};
sub2[s2] = "S";
query["$and"].push(sub1);
query["$and"].push(sub2);
arr.push(query);
};
我想获得colours.WH.size_code_id
,但不断获得colours.undefined.size_code_id
我缺少什么,任何建议非常感谢
答案 0 :(得分:2)
在
之后删除;
for (var i = 0; i < varray.length; i++) ; {
实施例
var varray = new Array("WH", "BL");
var fname = "colours",
lname = "size_code_id";
var arr = new Array();
var mquery = {
"$or": []
};
for (var i = 0; i < varray.length; i++) {
var query = {
"$and": []
};
var s1 = fname.concat(".").concat(varray[i]);
var s2 = fname.concat(".").concat(varray[i]).concat(".").concat(lname);
var sub1 = {}, sub2 = {};
sub1[s1] = {
$exists: 1
};
sub2[s2] = "S";
query["$and"].push(sub1);
query["$and"].push(sub2);
arr.push(query);
};
console.log(arr)