2013-10-25 2 views
1

다음 유형의 json이 있습니다.jquery를 사용하여 여러 개의 중복 값을 필터링하는 방법은 무엇입니까?

{ 
    "19": { 
     "entity_id": "19", 
      "type_id": "simple", 
      "sku": "Dell laptop", 
      "description": "The Inspiron 15R laptop features a 15.6\" screen, color options and up to 3rd Gen Intel® Core™ processors to keep you stylish and connected.", 
      "short_description": "The Inspiron 15R is a well-balanced laptop with something for everyone. Unless you need longer battery life, there's no need to spend more.", 
      "meta_keyword": "The Inspiron 15R is a well-balanced laptop with something for everyone. Unless you need longer battery life, there's no need to spend more.", 
      "name": "dell inspiron 15r", 
      "meta_title": "Laptop | Dell | Inspiron15R", 
      "meta_description": "The Inspiron 15R is a well-balanced laptop with something for everyone. Unless you need longer battery life, there's no need to spend more.", 
      "regular_price_with_tax": 32500, 
      "regular_price_without_tax": 32500, 
      "category_name": "Laptop", 
      "category_id": "19", 
      "final_price_with_tax": 31000, 
      "final_price_without_tax": 31000, 
      "is_saleable": "1", 
      "image_url": "http://192.168.18.171/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/h/o/how-to-deal-with-hp-laptop-power-issues.jpg" 
    }, 
     "20": { 
     "entity_id": "20", 
      "type_id": "simple", 
      "sku": "Sony Laptop", 
      "description": "Although Sony made computers in the 1980s exclusively for the local (Japan) market, the company withdrew from the computer business around the turn of the decade. Sony's re-entry to the global computer market under the new VAIO brand, began in 1996 with the PCV series of desktops", 
      "short_description": "Originally an acronym of Video Audio Integrated Operation, this was amended to Visual Audio Intelligent Organizer in 2008 to celebrate the brand's 10th anniversary", 
      "meta_keyword": "Originally an acronym of Video Audio Integrated Operation, this was amended to Visual Audio Intelligent Organizer in 2008 to celebrate the brand's 10th anniversary", 
      "name": "Sony VAIO", 
      "meta_title": "Laptop | Sony | VAIO", 
      "meta_description": "Originally an acronym of Video Audio Integrated Operation, this was amended to Visual Audio Intelligent Organizer in 2008 to celebrate the brand's 10th anniversary", 
      "regular_price_with_tax": 34299, 
      "regular_price_without_tax": 34299, 
      "category_name": "Laptop", 
      "category_id": "19", 
      "final_price_with_tax": 33000, 
      "final_price_without_tax": 33000, 
      "is_saleable": "1", 
      "image_url": "http://192.168.18.171/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/s/o/sony-vaio-vpcea1bgn-bi-2.jpg" 
    }, 
     "21": { 
     "entity_id": "21", 
      "type_id": "simple", 
      "sku": "HTC Mobiles", 
      "description": "HTC is the creator of many award-winning mobile devices and industry firsts. HTC's portfolio includes smartphones and tablets powered by HTC Sense™", 
      "short_description": "HTC is the creator of many award-winning mobile devices and industry firsts. HTC's portfolio includes smartphones and tablets powered by HTC Sense™", 
      "meta_keyword": "HTC is the creator of many award-winning mobile devices and industry firsts. HTC's portfolio includes smartphones and tablets powered by HTC Sense™", 
      "name": "HTC Desire X Dual Sim", 
      "meta_title": "SmartPhones | HTC | DESIRE X", 
      "meta_description": "HTC is the creator of many award-winning mobile devices and industry firsts. HTC's portfolio includes smartphones and tablets powered by HTC Sense™", 
      "regular_price_with_tax": 13500, 
      "regular_price_without_tax": 13500, 
      "category_name": "Smartphones", 
      "category_id": "20", 
      "final_price_with_tax": 13500, 
      "final_price_without_tax": 13500, 
      "is_saleable": "1", 
      "image_url": "http://192.168.18.171/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/h/t/htx-desire-x-ii.jpg" 
    }, 
     "22": { 
     "entity_id": "22", 
      "type_id": "simple", 
      "sku": "Nokia Mobiles", 
      "description": "Award-winning PureView technology, Carl Zeiss optics and six physical lenses. The Nokia Lumia 925 lets you capture the great moments, day or night.", 
      "short_description": "Award-winning PureView technology, Carl Zeiss optics and six physical lenses. The Nokia Lumia 925 lets you capture the great moments, day or night.", 
      "meta_keyword": "Award-winning PureView technology, Carl Zeiss optics and six physical lenses. The Nokia Lumia 925 lets you capture the great moments, day or night.", 
      "name": "Nokia Lumia 925", 
      "meta_title": "SmartPhones | Nokia | Lumia 925", 
      "meta_description": "Award-winning PureView technology, Carl Zeiss optics and six physical lenses. The Nokia Lumia 925 lets you capture the great moments, day or night.", 
      "regular_price_with_tax": 29930, 
      "regular_price_without_tax": 29930, 
      "category_name": "Smartphones", 
      "category_id": "20", 
      "final_price_with_tax": 29930, 
      "final_price_without_tax": 29930, 
      "is_saleable": "1", 
      "image_url": "http://192.168.18.171/magento/media/catalog/product/cache/0/image/9df78eab33525d08d6e5fb8d27136e95/n/o/nokia-lumia-925.jpg" 
    } 
} 

은 지금은 내가 유일한 방법 카테고리 이름 만

<script type="text/javascript"> 
    $(document).on('pageshow', function() { 
    $.mobile.loading('show'); 
    $.getJSON("http://vinoth.com/magento/api/rest/products", function (data) { 
     var uniqueCategory = []; 
     $.each(data, function (i, row) { 
      if ($.inArray(row.category_name, uniqueCategory) === -1) uniqueCategory.push(row.category_name) 

     }); 
     for (var i = 0; i < uniqueCategory.length; i++) { 
      $("#category").append('<li><a href="#"><h2>' + uniqueCategory[i] + '</h2></a></li>') 
     } 
     $("#category").listview('refresh'); 
     $.mobile.loading('hide'); 
    }); 
    }); 
</script> 

에 필터 다음과 같은 방법을 사용하려고하고있는 목록보기를 추가 할 categor ID와 categroy 이름 값의 중복을 필터링 할 CATEGORY_ID 및 CATEGORY_NAME 모두를 필터링? .I는 ID와 이름을 모두 추가 할

+0

"필터"란 무엇을 의미합니까? 병합 하시겠습니까? 풀다? – Jared

+0

코드는 두 가지 범주로 나뉩니다. 그런 다음 해당 범주 아래에 각 항목을 추가 하시겠습니까? listview에서'auto-dividers'를 사용할 것인가? – Omar

답변

0

변경이

 var dict = {}; 
    $.each(data, function(i, row) { 

    if(!dict.hasOwnProperty(row.category_id;)){ 
    dict[id] = row.category_name; 

    //DO YOUR UI THING HERE 
    } 

    }); 
에 성공 콜백
+0

매개 변수 url을 전달하기위한 id 값을 얻는 방법 – Ben10

+0

다른 질문을하고 있습니다. 이 솔루션은 아약스 호출 결과에서 중복 된 카테고리 ID와 카테고리 이름을 필터링합니다. – eggward

+0

필터를 죄송합니다. 콜백 성공 후 ID와 이름을 추가하고 싶습니다. category-name Ben10

관련 문제