私信  •  关注

Bergi

Bergi 最近创建的主题
Bergi 最近回复了

如果要查找满足特定条件的一个或多个对象,可以使用 query-js

//will return all elements with an id larger than 1
data.items.where(function(e){return e.id > 1;});
//will return the first element with an id larger than 1
data.items.first(function(e){return e.id > 1;});
//will return the first element with an id larger than 1 
//or the second argument if non are found
data.items.first(function(e){return e.id > 1;},{id:-1,name:""});

还有一个 single 和A singleOrDefault 他们的工作方式很像 first firstOrDefault 分别是。唯一的区别是如果 更多 找到多个匹配项。

有关查询JS的进一步解释,您可以从这里开始 post

12 年前
回复了 Bergi 创建的主题 » 在MongoDB上复制每个具有不同ID的文档[副本]

只有当对象相似时,才有可能使用原型解决方案:

function Cons(g) { this.good = g; }
Cons.prototype.bad = "something common";
var array = [new Cons("something 1"), new Cons("something 2"), …];

但是很简单(而且 O(1) ):

delete Cons.prototype.bad;