Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs中json数组的复选框过滤器_Angularjs - Fatal编程技术网

Angularjs中json数组的复选框过滤器

Angularjs中json数组的复选框过滤器,angularjs,Angularjs,我已经创建了一个过滤器,但是这个过滤器不能在数组中使用数组 'http://plnkr.co/edit/oygy79j3xyoGJmiPHm4g?p=info' 上面的plkr链接正在运行演示 app.filter('checkboxFilter', function($parse) { var cache = { //create an cache in the closure result: [], checkboxData: {} };

我已经创建了一个过滤器,但是这个过滤器不能在数组中使用数组

'http://plnkr.co/edit/oygy79j3xyoGJmiPHm4g?p=info'
上面的plkr链接正在运行演示

app.filter('checkboxFilter', function($parse) {
    var cache = { //create an cache in the closure
        result: [],
        checkboxData: {}
    };

    function prepareGroups(checkboxData) {
        var groupedSelections = {};
        Object.keys(checkboxData).forEach(function(prop) {

            //console.log(prop);

            if (!checkboxData[prop]) {
                return;
            } //no need to create a function

            var ar = prop.split('=');

            //console.log("ar is - "+ar);
            if (ar[1] === 'true') {
                ar[1] = true;
            } //catch booleans
            if (ar[1] === 'false') {
                ar[1] = false;
            } //catch booleans

            /* replacing 0 with true for show all offers */
            if(ar[0]=='SplOfferAvailable.text'){
                ar[1]='true';
            }else{

            }

            //make sure the selection is there!
            groupedSelections[ar[0]] = groupedSelections[ar[0]] || [];
            //at the value to the group.

            groupedSelections[ar[0]].push(ar[1]);
        });
        return groupedSelections;
    }

    function prepareChecks(checkboxData) {

        var groupedSelections = prepareGroups(checkboxData);

        var checks = [];

        //console.log(groupedSelections);
        Object.keys(groupedSelections).forEach(function(group) {
            //console.log("groupedSelections- "+groupedSelections);
            //console.log("group- "+group);
            var needToInclude = function(item) {
                //console.log("item- "+item);
                // use the angular parser to get the data for the comparson out.
                var itemValue = $parse(group)(item);

                var valueArr = groupedSelections[group];
                //console.log("valueArr- "+valueArr);

                function checkValue(value) { //helper function
                    return value == itemValue;
                }
                //check if one of the values is included.
                return valueArr.some(checkValue);
            };
            checks.push(needToInclude); //store the function for later use
        });
        return checks;
    }

    return function(input, checkboxData, purgeCache) {

        if (!purgeCache) { //can I return a previous 'run'?
            // is the request the same as before, and is there an result already?
            if (angular.equals(checkboxData, cache.checkboxData) && cache.result.length) {
                return cache.result; //Done!
            }
        }
        cache.checkboxData = angular.copy(checkboxData);


        var result = []; // this holds the results


        //prepare the checking functions just once.
        var checks = prepareChecks(checkboxData);



        input.every(function(item) {
            if (checks.every(function(check) {
                    return check(item);

                })) {
                result.push(item);
            }
            return result.length < 10000000; //max out at 100 results!
        });

        cache.result = result; //store in chache
        return result;
    };
});
以上代码用于复选框过滤器

当我点击名为Availability的复选框时,它不会过滤结果

请帮帮我


谢谢。

我认为您通过json导航的方式是错误的,因为如果您以这种方式输入,它就会工作

"Location": "Riyadh",
"AvlStatus": "AVAILABLE"
"Rooms": {.....

您必须以某种方式浏览房间,现在我认为您没有这样做

您的链接不起作用,请将您的一些代码放在这里。嘿,伙计们,请再次点击,抱歉给您带来不便。添加plunker链接时,请在帖子中包含您的代码,不要这样欺骗谢谢maurycy的建议,现在我已经在这里包括了一些代码,首先非常感谢。是的,你完全正确,但我不能这样做。我从第三方服务获取Xml,并将Xml信息转换为json。