例如,给定以下结构
pages = [
[
{ myvar: 1},
{ myvar: 2},
{ myvar: 3},
]
];
我如何表达愚蠢(类似python)的理解?
v.myvar for p in pages for v in p
答案 0 :(得分:6)
AFAIK,您不能,请参阅:https://github.com/jashkenas/coffee-script/issues/1191
同时解决方法(直到CoffeeScript得到改进):
pages = [
[
{ myvar: 1},
{ myvar: 2},
{ myvar: 3},
]
];
result = []
for row in pages
for map in row
result.push map.myvar
console.log result
输出:
[ 1, 2, 3 ]