2017-02-26 2 views
0

JS 의존 얻을 :통지 길이 ReadFlag에

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 싶어한다.

이 내 JSON에 대한 링크가 https://api.myjson.com/bins/navph

+0

당신이 원하는 정확히 명확히하십시오 수 있을까? ** ** 또는 ** ** 항목 중 _ReadFlag_ 0이 하나만있는 길이를 원하십니까? – caisah

+0

모든 항목에 ReadFlag가있는 길이를 원합니다. – poojay

답변

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(); 
+0

나는 이것을 시도했습니다. readflag가 0인지 1인지에 관계없이 여전히 전체 길이를 반환합니다. – poojay