이미 참조 된 JSON 데이터가있는 for()
루프를 만들려고합니다. 문제는 내 루프 변수 (이 경우 i
)를 참조하는 요소의 끝에 추가하는 것입니다. 예를 들어for 루프를 JSON 객체/배열 요소와 함께 사용 하시겠습니까?
는 내 JSON 구조는 버려진 :
{
"url": "http://www.example.com",
"rid": 1,
"rname": "Apple iPhone 4 Rotation",
"rmin": 90,
"rmax": 150,
"blank": 0,
"geo_country_0": "GB",
"geo_url_0": "http://en",
"geo_country_1": "FR",
"geo_url_1": "http://fr",
"geo_country_2": "ES",
"geo_url_2": "http://es"
}
geo_country_
의 경우
하고 및 geo_url_
가 I이 경우 루프 변수에 숫자를 추가 할 필요가있다. 더 나은 이해를위한
루프에 대한 나의 실제를
:하여i
[i]
처럼을 감싸는
- :
지금까지 해봤for(i = 1; i < count; i++) { $('#geo-location').append('<div id="glt_' + i + '" class="clone"><select name="g_country['+i+']" class="glt-input-c">' + options + '</select><input type="text" name="g_url[' + i + ']" class="glt-input-c" value="' + data.geo_url_i+ '"/></div>'); $('select[name="g_country['+i+']"').find('option[value="' + data.geo_country_i+ '"]').attr('selected','selected'); }
.
\i
처럼 이스케이프 처리 중입니다. (이것은 아마 어리석은 생각이었습니다).- 프리 픽킹
+
을 추가하면,+ data.geo_country + i +
입니다.
i
을 올바르게 해석하려면 어떻게해야합니까?
도움이 될 것입니다.
data['geo_country_' + i]
같은
'data [ 'geo_country _'+ i]'처럼'data.geo_country_? '를 참조하려고합니까? – dgilland