0

JS:

 function getJSON(){
                $.ajax({
                    url: "getgroupednotification.json",
                    type: "GET",
                    crossDomain: true,
                    success:function(res){

                        $.each(res,function(index, value){
                            //console.log(res);
                            //console.log(value);
                            $.each(value.Notifications, function(index_, value_){
                                if(value.Source == 'CIRIS'){
                                    var i = value.Notifications.length;
                                        if(value_.ReadFlag != 1){

                                    }
                                }
                            });
                       });
                 });

如果ReadFlag == 0,我想获得notification.length。我在这个例子中使用Source == CIRIS。

这是我的 JSON https://api.myjson.com/bins/navph的链接

4

1 回答 1

0

你可以使用这样的东西:

function getJSON() {
    $.ajax({
        url: "https://api.myjson.com/bins/navph",
        type: "GET",
        crossDomain: true,
        success: function(res) {
           var lens = res.filter(function(item) {
               // filter by source
               return item.Source === 'CIRIS';
           }).map(function(item) {
               // get only Notifications
               return item.Notifications;
           }).map(function(notification){
               // get lengths of notifications which have at least 1 RedFlag not 0
               return (notification.filter(function(item){
                   return item.RedFlag !== 0;
               }).length)
           })
           console.log(lens[0]);
        }
    })
}

getJSON();
于 2017-02-26T11:40:44.273 回答