如何跳过数组元素.map
?
我的代码:
var sources = images.map(function (img) {
if(img.src.split('.').pop() === "json"){ // if extension is .json
return null; // skip
}
else{
return img.src;
}
});
Run Code Online (Sandbox Code Playgroud)
这将返回:
["img.png", null, "img.png"]
Run Code Online (Sandbox Code Playgroud) {'country': 'France', 'collected': '2018-03-12', 'active': true}
{'country': 'France', 'collected': '2018-03-13', 'active': true}
{'country': 'France', 'collected': '2018-03-14', 'active': false}
{'country': 'Canada', 'collected': '2018-02-01', 'active': false}
{'country': 'Canada', 'collected': '2018-02-02', 'active': true}
Run Code Online (Sandbox Code Playgroud)
假设我有这个结果集,我想按国家对它们进行分组.按国家对它们进行分组后,结果如下:
{'country': 'France', 'collected': '2018-03-14', 'active': false}
{'country': 'Canada', 'collected': '2018-02-02', 'active': true}
Run Code Online (Sandbox Code Playgroud)
但是,我要排除结果,其中最后一排active
是false
(同一个国家的老行可以是真或假并不重要,只要最后一行等于true),我怎么能在elasticsearch做到这一点?这是我的查询:
POST /test/_search?search_type=count
{
"aggs": {
"group": {
"terms": {
"field": "country"
},
"aggs": {
"group_docs": {
"top_hits": {
"size": 1,
"sort": [
{
"collected": {
"order": "desc"
}
}
]
}
} …
Run Code Online (Sandbox Code Playgroud) 我有一个在生产中运行的nodejs脚本
我不太可能(曾经一千次)得到这样的错误:
TypeError: value is out of bounds
at checkInt (buffer.js:1009:11)
at Buffer.writeUInt16LE (buffer.js:1067:5)
at Object.foo.bar (/fake/path/name.js:123:1);
at Object.foo.bar2 (/fake/path/name2.js:123:1);
at Object.foo.bar3 (/fake/path/name3.js:123:1);
Run Code Online (Sandbox Code Playgroud)
导致生产服务器崩溃......
太棒了我有一个堆栈跟踪!但我想知道每个电话或所有数据的当前数据是什么?
有什么好的工具或代码可用于生产代码的错误记录(使用它的当前数据)?
例如:我有一个带有外键的“历史”表,它可能指向不同的表/实体,具体取决于字段值。
表历史:
create table history(
id int PimaryKey AUTO_INC,
elementid int, (ForeignKey)
elementtype varchar
)
Run Code Online (Sandbox Code Playgroud)
该表已填充,例如:
id ElementId ElementType
1 1 Device
2 2 Simcard
3 2 Simcard
Run Code Online (Sandbox Code Playgroud)
这告诉我们有
目标是拥有一个可用于多个实体的表。
这是集成动态外键的正确方法吗?我还想到的是创建一个包含表/实体的列表以供参考,因此该表将如下所示:
ALTER TABLE history MODIFY ElementType INTEGER;
Run Code Online (Sandbox Code Playgroud)
ElementType 将指:
create table entities(
id int PimaryKey AUTO_INC,
name varchar
)
Run Code Online (Sandbox Code Playgroud)
填充新表历史记录,例如:
id ElementId ElementType
1 1 1
2 2 2
3 2 2
Run Code Online (Sandbox Code Playgroud)
实体表被填充,例如:
id name
1 Device
2 Simcard
Run Code Online (Sandbox Code Playgroud) 这是代码的链接:
http://plnkr.co/edit/usrmiNkj5YJY5SlV8ETw?p=preview
打开你的javascript控制台,然后点击"打个招呼".它将触发$ apply已经在进行中的错误.
但是当你删除这段代码时:
ng-controller="mouseEvents" ng-mousedown="onMouseDown()" ng-mouseup="onMouseUp()" ng-mousemove="onMouseMove()"
Run Code Online (Sandbox Code Playgroud)
当你点击"打个招呼"保存后,错误就消失了.
我怎么解决这个问题?
我需要mouseEvents来设置标志,如果鼠标关闭或者它是多个不同的控制器.我不能简单地在我的代码中删除它.
编辑:
较新的角度版本在没有$ timeout v1.3.10或更高版本的情况下解决了我的问题