访问变量里面的过滤功能

时间:2013-09-27 18:21:18

标签: javascript underscore.js

如何在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)
    });
});

1 个答案:

答案 0 :(得分:4)

searchStr功能的参数中删除filter

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