问题描述
您能否建议最有效的搜索Immutable.Map值的方法? 我希望返回第一场比赛。
我相信我应该得到一个map.valueSeq()
并从那里去。
我正在尝试做这样的事情:
Immutable= require("immutable")
var keys = Immutable.Map()
k=keys.set(1,2)
var result = null
k.valueSeq().map(
function(value) {
if(value == 2)
result = value
}
)
return result
我想坚持使用Map数据结构,该结构在代码的其他地方使用。
1楼
Igor Dubinskiy
5
已采纳
2015-07-25 18:47:56
您可以使用 :
var Immutable = require("immutable");
var map = Immutable.Map();
var m = map.set(1,2);
return m.find(function(val) {
return val === 2;
});
您也可以使用m.valueSeq().find
。
2楼
Juan Caicedo
0
2016-02-29 16:44:19
Immutable.Map.Find
例
var map = Immutable.Map()
map = map.set(1,2) //set or add data to map
var criteria=2;
var finded=map.find(function(data,key) {
return data===criteria;//return the first value of data that return true
}, null);//return null if not found data
参见jsfiddle: ://jsfiddle.net/fyr5nk4x/