创建数组对象jquery

时间:2014-04-01 13:15:33

标签: javascript jquery arrays

我需要创建一个对象以支持过滤器,但我不确定如何构建它?我有一个具有X列数的csv文件。用户将选择列,然后在输入框中输入条件(我已经构建了这个)。我需要让对象看起来如下所示:

// an example filters object
var filters = {
    'Country': ['Canada', 'United States of America'],
    'Element': ['Page1_A0']
};

这是我在Stackoverflow上选择的过滤器。在此示例中,csv减少,其中Country = Canada或United States,Element = Page1_A0。这很好用,但我需要动态构建过滤器。希望你能帮忙。

//filter rows with a filter on one or more columns, Example: 'Country': ['Canada'],
            data = data.filter(function (row) {

                // run through all the filters, returning a boolean as true if mycolumns are found
                return mycolumns.reduce(function (pass, column) {

                    return pass && (
                        // pass if no filter is set
                        !filters[column] ||
                        // pass if the row's value is equal to the filter
                        // (i.e. the filter is set to a string)
                        row[column] === filters[column] ||
                        // pass if the row's value is in an array of filter values
                        filters[column].indexOf(row[column]) >= 0
                        );                  
                }, true);
            })

0 个答案:

没有答案