<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="blog">
<div class="blogPost">
<div class="postTitre">title</div>
<div class="closeDelete">
<input type="text" name="txtID" readonly="readonly" value="123" />X
<div class="close-text">DELETE</div>
</div>
</div>
<div class="blogPost">
<div class="postTitre">title</div>
<div class="closeDelete">
<input type="text" name="txtID" readonly="readonly" value="342" />X
<div class="close-text">DELETE</div>
</div>
</div>
<div class="blogPost">
<div class="postTitre">title</div>
<div class="closeDelete">
<input type="text" name="txtID" readonly="readonly" value="486" />X
<div class="close-text">DELETE</div>
</div>
</div>
</div>
上面是我的代码,我的问题是,Specimen.find({&#34; taxonomy.class&#34;:filter_spec},它的工作原理。但是当放入文本时(&#34; taxonomy.class& #34;等等)在一个变量中,它不再起作用了。如果我不能完成这项工作,那将是非常低效的,因为我必须处理好几个案例。
答案 0 :(得分:0)
如果要将object属性放在变量中,则需要使用 square bracket notation 来构造字段对象,如下所示:
var query = { },
projection = {
// Get only the taxonomy stuff
"taxonomy.phylum": 1,
"taxonomy.class": 1,
"taxonomy.order": 1,
"taxonomy.family": 1,
"taxonomy.genus": 1,
"taxonomy.species": 1,
"common_name": 1,
"last_edit": 1
};
query[filter_fin] = filter_spec;
Specimen.find(query, projection, callback);
或使用computed property names (ES6):
var query = {
[filter_fin]: filter_spec
},
projection = {
// Get only the taxonomy stuff
"taxonomy.phylum": 1,
"taxonomy.class": 1,
"taxonomy.order": 1,
"taxonomy.family": 1,
"taxonomy.genus": 1,
"taxonomy.species": 1,
"common_name": 1,
"last_edit": 1
};
Specimen.find(query, projection, callback);