JSON 개체를 호출하여 jquery를 사용하여 ajax 검색을 만들려고합니다. 현재 다음과 같은 형식의 개체에서 결과를 반복 할 수 있습니다.
[{
"ID": "4207b2d5b8994bd8a19c28815c07663d",
"position": 1,
"voteUpCount": 16,
"voteDownCount": 32,
"categories": [{
"position": 1,
"category": "7d435c8a70f7447ea03d4cbba11f4686"
}],
"keywords": [
"key-word"
],
"title": "This is a title",
"body": "<p>this is description</p>",
"outdated": false,
"slug": "this-is-an-article",
"views": 0,
"labelName": [
""
],
"locale": "gb",
"storeName": "mystore",
"id": 4207
},{
"ID": "4207b2d5b8994bd8a19c28815c07663d",
"position": 1,
"voteUpCount": 16,
"voteDownCount": 32,
"categories": [{
"position": 1,
"category": "7d435c8a70f7447ea03d4cbba11f4686"
}],
"keywords": [
"key-word"
],
"title": "This is a title",
"body": "<p>this is description</p>",
"outdated": false,
"slug": "this-is-an-article",
"views": 0,
"labelName": [
""
],
"locale": "gb",
"storeName": "mystore",
"id": 4207
} ]
다음을 사용하여 결과를 작성할 수 있습니다.
$.each(data, function(key, value){
article_data += '<div class="faq-item" data-artcile><a href="#">'+ value.title +'</a><i class="fa fa-chevron-down"></i></div>';
article_data += '<div class="faq-answer">'+ value.body +'</div>';
});
내가 가진 문제는 내 프로덕션 JSON 객체가 다음과 같이 응답으로 래핑된다는 것입니다.
{
"response": [{
"ID": "4207b2d5b8994bd8a19c28815c07663d",
"position": 1,
"voteUpCount": 16,
"voteDownCount": 32,
"categories": [{
"position": 1,
"category": "7d435c8a70f7447ea03d4cbba11f4686"
}],
"keywords": [
"key-word"
],
"title": "This is a title",
"body": "<p>this is description</p>",
"outdated": false,
"slug": "this-is-an-article",
"views": 0,
"labelName": [
""
],
"locale": "gb",
"storeName": "mystore",
"id": 4207
},{
"ID": "4207b2d5b8994bd8a19c28815c07663d",
"position": 1,
"voteUpCount": 16,
"voteDownCount": 32,
"categories": [{
"position": 1,
"category": "7d435c8a70f7447ea03d4cbba11f4686"
}],
"keywords": [
"key-word"
],
"title": "This is a title",
"body": "<p>this is description</p>",
"outdated": false,
"slug": "this-is-an-article",
"views": 0,
"labelName": [
""
],
"locale": "gb",
"storeName": "mystore",
"id": 4207
} ],
"http_code": 200
}
따라서 결과 HTML을 작성하는 데 사용하는 코드가 작동하지 않습니다. 루프에서 대상 키를 찾을 수 없기 때문입니다.
문제는 이 래핑 된 개체를 어떻게 올바르게 반복 할 수 있습니까?
예를 들어이 형식을 사용하여 성공하지 못했습니다.
value.response.title
어떤 도움을 주시면 감사하겠습니다.
응답 변수 'data.response'에있는 모든 데이터가 도움이 되었기를 바랍니다.
$.each(data.response, function(key, value){
article_data += '<div class="faq-item" data-artcile><a href="#">'+ value.title +'</a><i class="fa fa-chevron-down"></i></div>';
article_data += '<div class="faq-answer">'+ value.body +'</div>';
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다