전역 변수 (codata
)의 배열을 editoptions
(jqGrid)의 옵션 배열로 전달하려고했습니다.Array (json)가 jqGrid의 editoptions 매개 변수에 전달되지 않음
--------- countries_list.php 다음 JSON 배열을 던졌습니다 ----- -----------
["ABU","AD","AE","AF" .... "ZA","ZM","ZW"]
다음과 같이 내 코드 서 ---- PHP 스크립트 (jqGrid 코드 포함) ----------
jQuery(document).ready(function(){
var codata = new Array();
$.getJSON('countries_list.php', function(list){
$.each(list, function(val) {
codata.push("'"+val+"'");
# --- Here alert() displays 'codata' with all the elements ---
});
});
$("#datatable").jqGrid({
......
// some code until colMode specs
......
{ name:'guco',
index:'guco',
edittype:'select',
width:90,
editable: true,
editoptions: {
formatter:'select',
value: codata # --- array is not passed, it comes empty ---
},
sortable: true,
resizable: false
},
.....
--------- jqGrid 코드가있는 PHP 스크립트 ----------
사전에이 문제를 해결하는 방법에 대한 힌트는?, 고맙습니다.
마리오 Benitez.- 내가 당신의 PHP 스크립트가 유효 JS 배열이 아닌 JSON 객체를 전달하고 보는 것과
비동기 작업으로 인해 배열에 데이터를 저장하는 데 문제가 발생할 수 있습니다. –
사실 비동기식 'codata'는 참조 할 시간이 정의되지 않았기 때문에 콜백입니다. – Zlatev