如何在filter函数内的匿名函数内访问searchStr变量?在searchStr下方显示0-n,我猜想是一个迭代器,用于遍历我尝试过滤的集合

IEG.vent.on("searchGroups", function (searchStr) {
    if (searchStr) {
        IEG.Router.navigate("search/" + searchStr);
    }
    else {
        IEG.Router.navigate();
    }

    var filteredArray = IEG.searchColl.models.filter(function (model,searchStr) {
       console.log(model.get("key") + searchStr)
    });
});

最佳答案

searchStr函数的参数中删除filter

var filteredArray = IEG.searchColl.models.filter(function (model) {
    console.log(model.get("key") + searchStr);
});

关于javascript - 过滤器函数内部的访问变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19057552/

10-13 00:25