var json ={"SnapPolygonList":{"SnapPolygon":[{"id":"1","polygonType":"1","color":{"r":"0","g":"255","b":"0"},"tips":"#1#","isClosed":"true","pointList":{"point":[{"x":"0.324415","y":"0.496516"},{"x":"0.538462","y":"0.486063"},{"x":"0.438127","y":"0.806620"},{"x":"0.269231","y":"0.759582"}]}},{"id":"2","polygonType":"1","color":{"r":"255","g":"0","b":"0"},"tips":"#2#","isClosed":"true","pointList":{"point":[{"x":"0.168896","y":"0.728223"},{"x":"0.650502","y":"0.780488"},{"x":"0.493311","y":"0.945993"},{"x":"0.143813","y":"0.970383"},{"x":"0.157191","y":"0.949477"}]}}]}};
var eventAttributes = {
'布防区域': [],
'撤防区域': [],
'开始检测时间': '00:00:00'
};
for (var snap of json.SnapPolygonList.SnapPolygon) {
var pointList = [];
for (var point of snap.pointList.point) {
pointList.push([point.x, point.y]);
}
if (snap.color.r === '0') {
eventAttributes['布防区域'].push({
'区域坐标': pointList,
'区域编号': snap.id
});
}
if (snap.color.r === '255') {
eventAttributes['撤防区域'].push({
'撤防区域': pointList,
'区域编号': snap.id
});
}
};
console.log(eventAttributes);
babel在线转换
复制代码进去,转换复制回来
es-check
检查代码是否适应某个环境
es-check es5 ./index.js