0

アンダースコアテンプレートでJSONを取得するためにこのようなことをしています

 <% _.each(CList, function(d) {
    var i = 0 
      _.each(d, function(Cdata) {
          console.log(Cdata)
         var pid=JSON.stringify(Cdata["_id"]);
         if(typeof(Cdata["LOCATION"]) !== "undefined"){
       %>
       <tr>
       <td><input type="checkbox" id="Check<%= i %>" onclick='myfunctioncustomer(this,id,"<%= Cdata['COMPANY'] %>"," <%= Cdata['FIRST NAME'] %>","<%= Cdata['LAST NAME'] %> ","<%= Cdata['COMPANY URL'] %> ","<%= Cdata['LINKEDIN URL'] %> ","<%= Cdata['PERSONAL URL'] %> ","<%= Cdata['TWITTER URL'] %> ","<%= Cdata['DESIGNATION'] %> ","<%= Cdata['LOCATION'] %> ","<%= Cdata['PHONE'] %> ",<%= pid %>)' value='<%= Cdata["EMAIL"]  %>' ></input></td>
       <td> <%= Cdata['COMPANY'] %> </td>
       <td> <%= Cdata['FIRST NAME'] +' ' +Cdata['LAST NAME'] %> </td>
       <td> <%= Cdata['LOCATION'] %></td>
       </tr>
      <% i++; 
      }
    })%>
  <% }); %>

結果は、同じ値を持つ2行のテーブルとしてjsonを取得します。次のようなものが得られます。

 Company Name                    Name            Location
 Mercury Interactive Germany     Georg Goller    Germany
 Mercury Interactive Germany     Georg Goller    Germany
 Mercury Interactive GmbH        Gunter Kraft    Germany
 Mercury Interactive GmbH        Gunter Kraft    Germany

私はここで何が間違っているのですか..重複を取り除きたい

私のJSONの構造:

       [{"SECTOR": "", "CITY": "Missassauga", "DESIGNATION": "ASCM II", "FIRST NAME":            "Michael", "LAST NAME": "Gambarotto", "COMPANY": "Mercury Interactive Corporation", "URL": "", "PHONE": "(416) 605-7872", "LOCATION": "Canada", "ADDRESS": "5800 Explorer Drive, Suite 320Missassauga, Ontario L4W5K9Canada", "_id": {"$oid": "50b5da3dea01a32302a6a2ae"}, "EMAIL": "mgambarotto@mercury.com", "SIZE": ""}, {"SECTOR": "", "CITY": "Missassauga", "DESIGNATION": "APM Major Account Manager", "FIRST NAME": "Tim", "LAST NAME": "Healey", "COMPANY": "Mercury Interactive Corporation", "URL": "", "PHONE": "(416) 706-0171", "LOCATION": "Canada", "ADDRESS": "5800 Explorer Drive, Suite 320Missassauga, Ontario L4W5K9Canada", "_id": {"$oid": "50b5da3dea01a32302a6abfc"}, "EMAIL": "thealey@mercury.com", "SIZE": ""}, {"SECTOR": "", "CITY": "Mississauga", "DESIGNATION": "AM Manager", "FIRST NAME": "Warren", "LAST NAME": "Borthwick", "COMPANY": "Mercury Interactive Corporate", "URL": "", "PHONE": "416-419-4370", "LOCATION": "Canada", "ADDRESS": "5060 Spectrum WaySuite 400 ON L4W 5N5MississaugaCanada", "_id": {"$oid": "50b5da3dea01a32302a6adbf"}, "EMAIL": "wborthwick@mercury.com", "SIZE": ""}]
4

1 に答える 1

1

あなたの最も内側_.eachは不要のようです:

  <% _.each(CList, function(Cdata, i) {
    var pid=JSON.stringify(Cdata["_id"]);
    if(typeof(Cdata["LOCATION"]) !== "undefined"){
      %>
      <tr>
      <td><input type="checkbox" id="Check<%= i %>" onclick='myfunctioncustomer(this,id,"<%= Cdata['COMPANY'] %>"," <%= Cdata['FIRST NAME'] %>","<%= Cdata['LAST NAME'] %> ","<%= Cdata['COMPANY URL'] %> ","<%= Cdata['LINKEDIN URL'] %> ","<%= Cdata['PERSONAL URL'] %> ","<%= Cdata['TWITTER URL'] %> ","<%= Cdata['DESIGNATION'] %> ","<%= Cdata['LOCATION'] %> ","<%= Cdata['PHONE'] %> ",<%= pid %>)' value='<%= Cdata["EMAIL"]  %>' ></input></td>
      <td> <%= Cdata['COMPANY'] %> </td>
      <td> <%= Cdata['FIRST NAME'] +' ' +Cdata['LAST NAME'] %> </td>
      <td> <%= Cdata['LOCATION'] %></td>
      </tr>
      <%
    }
  }); %>
于 2013-02-13T08:36:04.770 に答える