2016-09-21 4 views
1

:를 사용하여 응답은 전 세계적으로

$.getJSON(_routes['salesInAMonthJS'], { month: "September 2016" }).then(
    function(d){ 
     console.log(d); 
    } 
); 

$.getJSON(_routes['salesInAMonthJS'], { month: "September 2016" }); 

는 날 다시 제공

{"9":{"name":"alex lloyd","country":"Germany","antiquity":"new client","amount":"0.0 USD"},"10":{"name" 
:"asdasdsadasda dasda","country":"Afghanistan","antiquity":"new client","amount":"0.0 USD"},"11":{"name" 
:"Alex Lloyd","country":"American Samoa","antiquity":"new client","amount":"0.0 USD"},"12":{"name":"alex 
lloyd","country":"Aruba","antiquity":"new client","amount":"0.0 USD"},"5":{"name":"surgeon bueno","country" 
:"Spain","antiquity":"renewal","amount":"2686.97 USD"}} 

그러나 때 사용자를 버튼을 클릭하면 저장된 데이터를 표시하고 싶습니다. d

예를 들어3210

:

$(document).on("click ", ".tick", function(e) { 
    e.preventDefault(); 
    $.each(d, function(i, item) { 
     &("div.container").append(d[i].name); 
    }); 
}); 

그러나이 모든 아이디어를 작동하지 않는 것 내가 무엇을 잘못하고 있어요? 감사합니다

+0

'& ("div.container")'는'$ ("div.container")'의 오타입니다. – Barmar

+1

가변 범위 문제가 있습니다. 'd'는'$ .getJSON' 콜백 함수에 국한되어 있으므로 다른 함수에서 액세스 할 수 없습니다. – Barmar

답변

0

이와 비슷한 것일까 요?

$.getJSON(geocodingAPI, function(json) { 
    $.json = json; 
}); 

$('button').on('click', function() { 
    alert($.json.status) 
}); 

http://jsfiddle.net/eywpvyrr/1/

0

d의 범위는 단지 콜백 함수이다. 클릭 바인딩을 이동하여 액세스 할 수 있습니다.

$.getJSON(_routes['salesInAMonthJS'], { month: "September 2016" }).then(function(d){ 
    $(document).on("click ", ".tick", function(e) { 
     e.preventDefault(); 
     $.each(d, function(i, item) { 
      $("div.container").append(d[i].name); 
     }); 
    }); 
}); 
관련 문제