나는 jquery .ajax 호출을 만들고 나는 json 결과를 기대하고있다. catch가 5 명의 작성자가 있다면 author_details_0, author_details_1, author_details_2 등을 얻을 수 있습니다. json에서 검색 할 변수의 이름을 동적으로 구성하려면 어떻게해야합니까? 내가 얼마나 많은 작가를 사귈 지 모르지만, 수백 명이있을 수 있습니다.Jquery Json 동적 변수 이름 생성
$.ajax({
type: "POST",
url: "/authordetails/show_my_details/",
data: af_pTempString,
dataType: "json",
beforeSend: function() {
},
success: function(jsonData) {
console.log("Incoming from backend : " + jsonData.toSource());
if(jsonData.AuthorCount)
{
console.log("Number of Authors : " + jsonData.AuthorCount);
for (i = 0; i < jsonData.AuthorCount; i++)
{
temp = 'author_details_' + i; <-------------------This is the name of the variable I'm expecting.
console.log("Farm information : " + eval(jsonData.temp)); <----- This doesn't work, how can I get jsonData.author_details_2 for example, 'coz I don't know how many authors are there, there could be hundreds.
}
}
해결 방법에 대한 의견이 있으면 알려 주시기 바랍니다. 많은 감사하겠습니다.
을 왜 등 author_details_0, 1, 2, 필요합니까? – yoda
json을 어떻게 생성합니까? – Eric
백엔드에서 django를 사용하고 있습니다. 내가 만든 데이터 모델에는 Author 및 관련 Author_Details 테이블이 있습니다. 게시자 ID가 주어지면 필자는 json_serializer.serialize (allAuthors, ensure_ascii = False)를 간단히 직렬화하는 Authors 집합을 쿼리하고 가져옵니다. 이것은 저자 세부 정보를 직렬화하지 않으므로 저자 객체 배열을 반복하고 수동으로 작성해야합니다. 따라서 author_details_XX는 저자 기본 키입니다. 저자 및 기타 세부 정보를 단일 JSON Array 객체로 묶는 방법이 있는지 잘 모르겠습니다. 기쁜 마음으로 내 코드를 개조 해 보겠습니다. – PlanetUnknown