我想格式化我的json响应,以便我可以动态地为我的模板提供数据.代码将使用一个获取数据jSON然后Im卡在那里.我可以单独提取数据,但我很好奇,如果我可以使用
jquery /
javascript.我也读到有一个名为Underscore.js的实用程序库来实现这一点.
[{ "division": "East","rm_name": "Russ Martin","address": "MT,VT,NH,ME (all firms)","state": "MT","coordinates": "43.299428,-74.217933" },{ "division": "East","rm_name": "Carey Fischer","address": "NY- Upstate ex Rockland County (BD,FP)","state": "NY","coordinates": "46.879682,-110.362566" },"rm_name": "Brandon Born","address": "CT,NY - Upstate,MA - ex metro Boston (FI),MA - Central,West (all firms)","state": "CT","coordinates": "40.714353,-74.005973" },"rm_name": "Joe Tocyloski","address": "PA - East,NJ - South (FP)","state": "PA","coordinates": "41.603221,-73.087749" },"rm_name": "Phil Hemery","address": "NJ (FI),NJ - Bergen County (all firms),NY - NYC (FI,RIA)/Westchester (FI,BD)/Rockland County (all firms)","state": "NJ","coordinates": "41.203456,-77.189941" },"rm_name": "Bob Mancini","address": "MA - East (all firms)","state": "MA","coordinates": "42.407235,-71.383667" },"rm_name": "Damien Ramondo","address": "NJ,PA East","rm_name": "Kevin Gang","address": "W VA,PA - West (all firms),OH - Cleveland (BD,FI)","state": "VA","coordinates": "44.314844,-85.602364" },"rm_name": "Andrew Fischer","address": "MI - (all firms)","state": "MI","coordinates": "40.057052,-74.404907" },"rm_name": "David Saslowsky","address": "NYC","rm_name": "Robert Brazofsky","rm_name": "Joseph Proscia","address": "NJ - North ex Bergen County,NY - NYC (FP)","rm_name": "William Marsalise","address": "NY - LI and Outer Boroughs (FI),LI Planners","rm_name": "Dan Stack","address": "OH - Columbus and South (all firms),KY - Covington (all firms)","state": "OH","coordinates": "37.439974,-78.662109" },"rm_name": "James Broderick","address": "OH - North of Columbus ex Cleveland (all firms),Cleveland (FP)",{ "division": "South","rm_name": "Chris Carrelha","address": "FL - North (FP)","state": "FL","coordinates": "40.417287,-82.907123" },"rm_name": "Don Connell","address": "TN,AR,KY - ex Covington (all firms),MO - St. Louis (by firm)","state": "TN","coordinates": "27.664827,-81.515754" },"rm_name": "Jay O'Connor","address": "NC - ex coast,SC,GA - Savannah to Augusta (all firms)","state": "NC","coordinates": "35.517491,-86.580447" },"rm_name": "Dwight Cornell","address": "FL - South,VI,PR (all firms)","rm_name": "Eric Indovina","address": "AL (all firms),GA (BD,RIA)","state": "AL","coordinates": "14.97198,19.753418" },"rm_name": "Russ Corby","address": "TX - DFW (BD,FP) Houston Austin and San Antonio (FP,"state": "TX","coordinates": "32.318231,-86.902298" },"rm_name": "Chris Boeker","address": "TX - Southeast (BD),MS,LA - South (all firms)","rm_name": "Robert Nelms","address": "VA - ex DC metro (all firms),NC - Coast,MD (ex Baltimore),VA,DC (FI),TN - northeastern corner (all firms)","rm_name": "Joe Dominguez","address": "FL - North (BD,"rm_name": "Marc Della Pia","address": "MD,DC - Metro,VA - Alexandria (BD,FA),Baltimore (FI)","state": "MD","coordinates": "31.968599,-99.901813" },"address": "GA (FI,"state": "GA","coordinates": "32.166313,-82.902832" },"rm_name": "Terry Harris","address": "OK,TX - by city (all firms)","state": "OK",{ "division": "West","rm_name": "Arend Elston","address": "AR,MO,IL - South(all firms)","state": "AR","coordinates": "35.007752,-97.092877" },"rm_name": "John Schmidt","address": "IL - Chicago Metro (BD)","state": "IL","coordinates": "35.20105,-91.831833" },"rm_name": "Jason Stevens","address": "MN,ND (All Firms)","state": "MN","coordinates": "46.7248,-94.680176" },"rm_name": "Laura Channell","address": "IL - Chicago Metro (FI,"rm_name": "Patrick Denis","address": "WI (all firms),Upper Peninsula of Michigan","state": "WI","coordinates": "46.729553,-94.6859" },"rm_name": "Michael Cheskis","address": "IN (all firms),IL - Chicago Metro (By Firm)","state": "IN","coordinates": "43.78444,-88.787868" },"rm_name": "Dave Mitchell","address": "IA,KS,NE,SD,MO - Kansas City (all firms)","state": "IA","coordinates": "40.271144,-86.132812" },"rm_name": "Paul Moyer","address": "WA,ID,OR (all firms)","state": "WA","coordinates": "41.877741,-93.098145" },"rm_name": "Peter Szabo","address": "AK,NV - Reno (all firms),N. CA (BD & FI),San Francisco (FI)","state": "AK","coordinates": "47.751074,-120.740139" },"rm_name": "Lou Tousignant","address": "N.CA (FP),San Francisco (BD & FP)","state": "CA","coordinates": "64.200841,-149.493673" },"rm_name": "Matt Malvey","address": "CA - San Diego (all firms)","rm_name": "Kevin Dausch","address": "N. CA (BD & FI),"rm_name": "Scott Hutton","address": "CO,NM,WY,MT (all firms)","state": "Colorado","coordinates": "40.747164,-74.000566" },"rm_name": "Brian Buehring","address": "CA - North LA to Santa Barbara,HI (all firms)","rm_name": "Robert Forrester","address": "CA - Orange County to San Diego (all firms)","rm_name": "Mike Ossmen","address": "CA - Downtown LA,Pasadena,South Bay & Inland Empire (All Firms)",-149.493673" }]
我可以使用jquery做这个吗?提前感谢任何建议.
解决方法
你可以轻松地用下划线来做.
var groupedData = _.groupBy(data,function(d){return d.division});