获取选定的JSON数据

时间:2014-04-25 15:09:09

标签: javascript jquery json

我有这样的JSON数据:

[{
    "RM_Name": "Russ Martin",
    "Division": "East",
    "RM_Phone": "(603) 491-1259",
    "RC_Name": "Jacob Sucoff",
    "RC_Phone": "(800) 247-4154 x3403",
    "States_Covered": "MT,VT, NH, ME  (all firms)",
    "Latitude": 46.6797995,
    "Longitude": -110.044783,
    "Coordinates": "46.6797995,-110.044783"
}, {
    "RM_Name": "Carey Fortnam",
    "Division": "East",
    "RM_Phone": "(585)-259-7394",
    "RC_Name": "Matt Wrzesniewsky",
    "RC_Phone": "(800) 247-4154 x3088",
    "States_Covered": "NY- Upstate ex Rockland County (BD, FP)",
    "Latitude": 40.7056308,
    "Longitude": -73.9780035,
    "Coordinates": "40.7056308,-73.9780035"
}, {
    "RM_Name": "Brandon Born",
    "Division": "East",
    "RM_Phone": "(860) 919-2998",
    "RC_Name": "Greg Curran",
    "RC_Phone": "(800) 247-4154 x3413",
    "States_Covered": "CT, NY - Upstate, MA - ex metro Boston (FI), MA - Central, West (all firms)",
    "Latitude": 41.5178234,
    "Longitude": -72.757507,
    "Coordinates": "41.5178234,-72.757507"
}, {
    "RM_Name": "Joe Tocyloski",
    "Division": "East",
    "RM_Phone": "(201) 314-7943",
    "RC_Name": "Eric Siegrist",
    "RC_Phone": "(800) 247-4154 x3113",
    "States_Covered": "PA - East, NJ - South (FP)",
    "Latitude": 40.9945928,
    "Longitude": -77.6046984,
    "Coordinates": "40.9945928,-77.6046984"
}, {
    "RM_Name": "Phil Hemery",
    "Division": "East",
    "RM_Phone": "(917) 583-1760",
    "RC_Name": "Ney Castro",
    "RC_Phone": "(800) 247-4154 x3062",
    "States_Covered": "NJ (FI), NJ - Bergen County (all firms), NY - NYC (FI,RIA)/Westchester (FI,BD)/Rockland County (all firms)",
    "Latitude": 40.1430241,
    "Longitude": -74.7311156,
    "Coordinates": "40.1430241,-74.7311156"
}, {
    "RM_Name": "Robert Mancini",
    "Division": "East",
    "RM_Phone": "(617) 549-1349",
    "RC_Name": "Charlie Kim",
    "RC_Phone": "(800) 247-4154 x3241",
    "States_Covered": "MA - East (all firms)",
    "Latitude": 42.0629399,
    "Longitude": -71.718067,
    "Coordinates": "42.0629399,-71.718067"
}, {
    "RM_Name": "Damien Ramondo",
    "Division": "East",
    "RM_Phone": "(610) 909-8955",
    "RC_Name": "William Wielgolewski",
    "RC_Phone": "(800) 247-4154 x3053",
    "States_Covered": "NJ, PA East",
    "Latitude": 40.1430241,
    "Longitude": -74.7311156,
    "Coordinates": "40.1430241,-74.7311156"
}, {
    "RM_Name": "Kevin Gang",
    "Division": "East",
    "RM_Phone": "(724) 407-3757",
    "RC_Name": "Michael Rus",
    "RC_Phone": "(800) 247-4154 x3052",
    "States_Covered": "W VA,PA - West (all firms), OH - Cleveland (BD, FI)",
    "Latitude": 38.0033854,
    "Longitude": -79.7715309,
    "Coordinates": "38.0033854,-79.7715309"
}, {
    "RM_Name": "Andrew Fischer",
    "Division": "East",
    "RM_Phone": "(248) 505-8211",
    "RC_Name": "Charlie Kim",
    "RC_Phone": "(800) 247-4154 x3114",
    "States_Covered": "MI - (all firms)",
    "Latitude": 44.9700413,
    "Longitude": -86.4158049,
    "Coordinates": "44.9700413,-86.4158049"
}, {
    "RM_Name": "David Saslowsky",
    "Division": "East",
    "RM_Phone": "(917) 620-6042",
    "RC_Name": "Matt Werner",
    "RC_Phone": "(800) 247-4154 x3025",
    "States_Covered": "NYC",
    "Latitude": 40.7056308,
    "Longitude": -73.9780035,
    "Coordinates": "40.7056308,-73.9780035"
}, {
    "RM_Name": "Robert Brazofsky",
    "Division": "East",
    "RM_Phone": "(917) 359-8113",
    "RC_Name": "Matt Werner",
    "RC_Phone": "(800)247-4154 x3405",
    "States_Covered": "NYC",
    "Latitude": 40.7056308,
    "Longitude": -73.9780035,
    "Coordinates": "40.7056308,-73.9780035"
}, {
    "RM_Name": "Joseph Proscia",
    "Division": "East",
    "RM_Phone": "(201) 233-2417",
    "RC_Name": "Matt Wrzesniewsky",
    "RC_Phone": "(800) 247-4154 x3091",
    "States_Covered": "NJ - North ex Bergen County, NY - NYC (FP)",
    "Latitude": 40.1430241,
    "Longitude": -74.7311156,
    "Coordinates": "40.1430241,-74.7311156"
}, {
    "RM_Name": "William Marsalise",
    "Division": "East",
    "RM_Phone": "(646) 703-4732",
    "RC_Name": "Nick Semko",
    "RC_Phone": "(800) 247-4154 3242",
    "States_Covered": "NY - LI and Outer Boroughs (FI), LI Planners",
    "Latitude": 40.7056308,
    "Longitude": -73.9780035,
    "Coordinates": "40.7056308,-73.9780035"
}, {
    "RM_Name": "Dan Stack",
    "Division": "East",
    "RM_Phone": "(937) 750-6112",
    "RC_Name": "Nick Semko",
    "RC_Phone": "(800) 247-4154 x3093",
    "States_Covered": "OH - Columbus and South (all firms), KY - Covington (all firms)",
    "Latitude": 40.1903624,
    "Longitude": -82.6692524,
    "Coordinates": "40.1903624,-82.6692524"
}, {
    "RM_Name": "James Broderick",
    "Division": "East",
    "RM_Phone": "(440) 596-2194",
    "RC_Name": "Jacob Sucoff",
    "RC_Phone": "(800) 247-4154 x3068",
    "States_Covered": "OH - North of Columbus ex Cleveland (all firms), Cleveland (FP)",
    "Latitude": 40.1903624,
    "Longitude": -82.6692524,
    "Coordinates": "40.1903624,-82.6692524"
}, {
    "RM_Name": "Christopher Carrelha",
    "Division": "South",
    "RM_Phone": "404-719-6860",
    "RC_Name": "Daryl Northrop",
    "RC_Phone": "(800)247-4154 x3097",
    "States_Covered": "FL - North (FP)",
    "Latitude": 27.975728,
    "Longitude": -83.8330166,
    "Coordinates": "27.975728,-83.8330166"
}, {
    "RM_Name": "Don Connell",
    "Division": "South",
    "RM_Phone": "(615) 424-1044",
    "RC_Name": "Mark Gleason",
    "RC_Phone": "(800) 247-4154 x3024",
    "States_Covered": "TN, AR, KY - ex Covington (all firms), MO - St. Louis (by firm)",
    "Latitude": 35.8304544,
    "Longitude": -85.9785989,
    "Coordinates": "35.8304544,-85.9785989"
}, {
    "RM_Name": "Jay O'Connor",
    "Division": "South",
    "RM_Phone": "(704) 516-5290",
    "RC_Name": "Grant Kunkel",
    "RC_Phone": "(800) 247-4154 x3177",
    "States_Covered": "NC - ex coast, SC, GA - Savannah to Augusta (all firms)",
    "Latitude": 35.2145629,
    "Longitude": -79.8912675,
    "Coordinates": "35.2145629,-79.8912675"
}, {
    "RM_Name": "Dwight Cornell",
    "Division": "South",
    "RM_Phone": "(239) 404-6608",
    "RC_Name": "Mark Gleason",
    "RC_Phone": "(800) 247-4154 x3020",
    "States_Covered": "FL - South, VI, PR (all firms)",
    "Latitude": 27.975728,
    "Longitude": -83.8330166,
    "Coordinates": "27.975728,-83.8330166"
}, {
    "RM_Name": "Eric Indovina",
    "Division": "South",
    "RM_Phone": "(205) 602-2767",
    "RC_Name": "Robert Amberger",
    "RC_Phone": "(800) 247-4154 x3205",
    "States_Covered": "AL (all firms), GA (BD, RIA)",
    "Latitude": 32.6010277,
    "Longitude": -86.6807364,
    "Coordinates": "32.6010277,-86.6807364"
}, {
    "RM_Name": "Russ Corby",
    "Division": "South",
    "RM_Phone": "(646) 696-0069",
    "RC_Name": "Natasha Fomenko",
    "RC_Phone": "(800) 247-4154 x3066",
    "States_Covered": "TX - DFW (BD, FP) Houston Austin and San Antonio (FP, FI)",
    "Latitude": 31.1693363,
    "Longitude": -100.0768425,
    "Coordinates": "31.1693363,-100.0768425"
}, {
    "RM_Name": "Chris Boeker",
    "Division": "South",
    "RM_Phone": "(713) 213-2990",
    "RC_Name": "Tom Perini",
    "RC_Phone": "(800) 247-4154 x3722",
    "States_Covered": "TX - Southeast (BD), MS, LA - South (all firms)",
    "Latitude": 31.1693363,
    "Longitude": -100.0768425,
    "Coordinates": "31.1693363,-100.0768425"
}, {
    "RM_Name": "Robert Nelms",
    "Division": "South",
    "RM_Phone": "(804) 814-4806",
    "RC_Name": "Grant Kunkel",
    "RC_Phone": "(800) 247-4154 x3239",
    "States_Covered": "VA - ex DC metro (all firms), NC - Coast, MD (ex Baltimore), VA, DC (FI), TN - northeastern corner (all firms)",
    "Latitude": 38.0033854,
    "Longitude": -79.7715309,
    "Coordinates": "38.0033854,-79.7715309"
}, {
    "RM_Name": "Joe Dominguez",
    "Division": "South",
    "RM_Phone": "(917) 299-8819",
    "RC_Name": "Daryl Northrop",
    "RC_Phone": "(800) 247-4154 x3116",
    "States_Covered": "FL - North (BD, FI)",
    "Latitude": 27.975728,
    "Longitude": -83.8330166,
    "Coordinates": "27.975728,-83.8330166"
}, {
    "RM_Name": "Marc Della Pia",
    "Division": "South",
    "RM_Phone": "(202) 384-2512 ",
    "RC_Name": "Jeremy Prawer",
    "RC_Phone": "(800) 247-4154 x3231",
    "States_Covered": "MD, DC - Metro, VA - Alexandria  (BD, FA), Baltimore (FI)",
    "Latitude": 38.8058411,
    "Longitude": -77.2684162,
    "Coordinates": "38.8058411,-77.2684162"
}, {
    "RM_Name": "Terry Harris",
    "Division": "South",
    "RM_Phone": "(214) 399-1472",
    "RC_Name": "Natasha Fomenko",
    "RC_Phone": "(800) 247-4154 x3429",
    "States_Covered": "OK, TX - by city (all firms)",
    "Latitude": 35.3097654,
    "Longitude": -98.7165585,
    "Coordinates": "35.3097654,-98.7165585"
}, {
    "RM_Name": "Arend Elston",
    "Division": "West",
    "RM_Phone": "(314) 566-6305",
    "RC_Name": "Zachary Bindler",
    "RC_Phone": "(800) 247-4154 x3060",
    "States_Covered": "AR, MO, IL - South(all firms)",
    "Latitude": 34.7519275,
    "Longitude": -92.1323668,
    "Coordinates": "34.7519275,-92.1323668"
}, {
    "RM_Name": "John Schmidt",
    "Division": "West",
    "RM_Phone": "(847) 910-4126",
    "RC_Name": "Thomas Lonergan",
    "RC_Phone": "(800) 247-4154 x3200",
    "States_Covered": "IL - Chicago Metro (BD)",
    "Latitude": 35.20105,
    "Longitude": -91.831833,
    "Coordinates": "35.20105,-91.831833"
}, {
    "RM_Name": "Jason Stevens",
    "Division": "West",
    "RM_Phone": "(763) 360-4365",
    "RC_Name": "Brian Paulson",
    "RC_Phone": "(800) 247-4154 x3067",
    "States_Covered": "MN, ND (All Firms)",
    "Latitude": 46.7248,
    "Longitude": -94.680176,
    "Coordinates": "46.7248,-94.680176"
}, {
    "RM_Name": "Laura Rupsis",
    "Division": "West",
    "RM_Phone": "(630) 441-8301",
    "RC_Name": "Kenny Meyer",
    "RC_Phone": "(800) 247-4154 x323",
    "States_Covered": "IL - Chicago Metro (FI, FP)",
    "Latitude": 39.7408263,
    "Longitude": -89.503508,
    "Coordinates": "39.7408263,-89.503508"
}, {
    "RM_Name": "Patrick Denis",
    "Division": "West",
    "RM_Phone": "(920) 362-2692",
    "RC_Name": "Zachary Bindler",
    "RC_Phone": "(800) 247-4154 x3132",
    "States_Covered": "WI (all firms), Upper Peninsula of Michigan",
    "Latitude": 44.7862909,
    "Longitude": -89.8267157,
    "Coordinates": "44.7862909,-89.8267157"
}, {
    "RM_Name": "Michael Cheskis",
    "Division": "West",
    "RM_Phone": "(317) 416-1938",
    "RC_Name": "Kenny Meyer",
    "RC_Phone": "(800)-247-4154 x3174",
    "States_Covered": "IN (all firms), IL - Chicago Metro (By Firm)",
    "Latitude": 39.7662195,
    "Longitude": -86.441277,
    "Coordinates": "39.7662195,-86.441277"
}, {
    "RM_Name": "Dave Mitchell",
    "Division": "West",
    "RM_Phone": "(954) 218-2632",
    "RC_Name": "Douglas Caggiano",
    "RC_Phone": "(800) 247-4154 x3090",
    "States_Covered": "IA, KS, NE, SD, MO - Kansas City (all firms)",
    "Latitude": 41.9383166,
    "Longitude": -93.39108,
    "Coordinates": "41.9383166,-93.39108"
}, {
    "RM_Name": "Paul Moyer",
    "Division": "West",
    "RM_Phone": "(425) 765-6798",
    "RC_Name": "Paul Hammer",
    "RC_Phone": "(800) 247-4154 x3103",
    "States_Covered": "WA, ID, OR (all firms)",
    "Latitude": -24.4400201,
    "Longitude": 120.9620539,
    "Coordinates": "(-)24.4400201,120.9620539"
}, {
    "RM_Name": "Peter Szabo",
    "Division": "West",
    "RM_Phone": "(646) 696-0065",
    "RC_Name": "Mark Quarno",
    "RC_Phone": "(800) 247-4154 x3237",
    "States_Covered": "AK, NV - Reno (all firms), N. CA (BD & FI), San Francisco (FI)",
    "Latitude": 61.3025006,
    "Longitude": -158.7696247,
    "Coordinates": "61.3025006,-158.7696247"
}, {
    "RM_Name": "Lou Tousignant",
    "Division": "West",
    "RM_Phone": "(415) 857-0655",
    "RC_Name": "Matthew Santora",
    "RC_Phone": "(800) 247-4154 x3220",
    "States_Covered": "N.CA (FP), San Francisco (BD & FP)",
    "Latitude": 37.2718745,
    "Longitude": -119.2704153,
    "Coordinates": "37.2718745,-119.2704153"
}, {
    "RM_Name": "Matt Malvey",
    "Division": "West",
    "RM_Phone": "(619) 937-1828",
    "RC_Name": "Mark Quarno",
    "RC_Phone": "(800) 247-4154 x3129",
    "States_Covered": "CA - San Diego (all firms)",
    "Latitude": 37.2718745,
    "Longitude": -119.2704153,
    "Coordinates": "37.2718745,-119.2704153"
}, {
    "RM_Name": "Kevin Dausch",
    "Division": "West",
    "RM_Phone": "(415) 279-4074",
    "RC_Name": "Matthew Santora",
    "RC_Phone": "(800)247-4154 x3050",
    "States_Covered": "N. CA (BD & FI), San Francisco (FI)",
    "Latitude": 37.2718745,
    "Longitude": -119.2704153,
    "Coordinates": "37.2718745,-119.2704153"
}, {
    "RM_Name": "Scott Hutton",
    "Division": "West",
    "RM_Phone": "(303) 514-0322",
    "RC_Name": "Paul Hammer",
    "RC_Phone": "(800) 247-4154 x3232",
    "States_Covered": "CO, NM, WY, MT (all firms)",
    "Latitude": 38.997934,
    "Longitude": -105.550567,
    "Coordinates": "38.997934,-105.550567"
}, {
    "RM_Name": "Bryan Pacana",
    "Division": "West",
    "RM_Phone": "(206) 681-6575",
    "RC_Name": "AB Sales Desk",
    "RC_Phone": "(800) 247-4154",
    "States_Covered": "CA - North LA to Santa Barbara, HI (all firms)",
    "Latitude": 37.2718745,
    "Longitude": -119.2704153,
    "Coordinates": "37.2718745,-119.2704153"
}, {
    "RM_Name": "Robert Forrester",
    "Division": "West",
    "RM_Phone": "(888) 805-4242",
    "RC_Name": "Mac Winchester",
    "RC_Phone": "(800) 247-4154 x3061",
    "States_Covered": "CA - Orange County to San Diego (all firms)",
    "Latitude": 37.2718745,
    "Longitude": -119.2704153,
    "Coordinates": "37.2718745,-119.2704153"
}, {
    "RM_Name": "Michael Ossmen",
    "Division": "West",
    "RM_Phone": "(626) 720-2314",
    "RC_Name": "Brian Lee",
    "RC_Phone": "(800) 247-4154 x3238",
    "States_Covered": "CA - Downtown LA, Pasadena, South Bay & Inland Empire (All Firms)",
    "Latitude": 37.2718745,
    "Longitude": -119.2704153,
    "Coordinates": "37.2718745,-119.2704153"
}]

我想要做的只是获取特定部门的数据,例如East只显示East。

$.getJSON('/proto/Alfred/ab-rm/data/rm_data.js', function (data) {
        $.each(data, function (i, item) {
            var rm_name = item.RM_Name, division = item.Division, rm_phone = item.RM_Phone, rc_name = item.RC_Name, rc_phone = item.RC_Phone, states = item.States_Covered;


        });

    });

上面的代码让我获取所有数据,如何修改此代码,以便我可以将它们分组或类似。抱歉,如果没有小提琴。谢谢。

2 个答案:

答案 0 :(得分:4)

您可以根据需要过滤数据......

$.getJSON('/proto/Alfred/ab-rm/data/rm_data.js', function (data) {
    var east = $(data).filter(function() {
        return this.Division === "East";
    });
});

这将返回分区为东的所有对象的数组。

<强> jsfiddle example


如果你想进行大量的过滤,那么我建议使用一个函数,沿着这些方向......

function dataByPropertyValue(data, property, value) {
    return $(data).filter(function() {
        return this[property] === value;
    });
}

$.getJSON('/proto/Alfred/ab-rm/data/rm_data.js', function (data) {
    east = dataByPropertyValue(data, "Division", "East");
    west = dataByPropertyValue(data, "Division", "West");
});

<强> jsfiddle example

答案 1 :(得分:-2)

尝试使用underscore.js。
它具有一整套用于分组,过滤,查找等功能。

var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
=> [2, 4, 6]

希望这有帮助。