2010-12-31 2 views
1

와 모달 폼을 채울 :내가 이렇게 만든 모달 폼을 JSON

function addeditNote(rowID,callback) { 
     var ret; 
     jQuery.fancybox({ 
      modal : true, 
      overlayOpacity : 0.25, 
      content : "<div class=\"contentbox modal-window modal-400\"><div class=\"boxbody\"><div class=\"boxheader clear\"><h2>Add/Edit User Notes</h2></div><br /><div class=\"box-wrap clear\"><form action=\"\" method=\"post\" class=\"form bt-space0\"><div class=\"columns clear bt-space0\"><div class=\"colText fl\"><div class=\"form-field clear\"><label for=\"textfield\" class=\"formlabel size-20 fl-space2\">Name: </label><input type=\"text\" id=\"name\" class=\"text fl-space2\" /></div><div class=\"form-field clear\"><div class=\"fl-space2\"><label for=\"textarea\" class=\"formlabel size-20\">Notes: </label></div><textarea id=\"note\" class=\"form-textarea display\" cols=\"50\" rows=\"6\" name=\"form[note]\" rel=\"textarea\"></textarea></div></div></div><div class=\"columns clear bt-space5\"></div><div class=\"form-field clear\"><input id=\"addeditNote_cancel\" class=\"button fr-space2\" type=\"button\" value=\"Cancel\"><input id=\"addeditNote_ok\" class=\"button green fr-space\" type=\"button\" value=\"Enter\"></div></form></div><!-- end of box-wrap --></div> <!-- end of box-body --></div>", 



      onComplete : function() { 
       jQuery("#addeditNote_cancel").click(function() { 
        ret = false; 
        jQuery.fancybox.close(); 
       }) 
       jQuery("#addeditNote_ok").click(function() { 
        ret = true; 
        jQuery.fancybox.close(); 
       }) 
      }, 
      onClosed : function() { 
       callback.call(this,ret); 
      } 
     }); 
} 

내가 얻을 내 JSON 문자열 같은 : 반환

$.getJSON("GetNotes.php?id=" + rowID, 
    function(data) { 
     $.each(data, function(i, item) { 
      $('#' + item.field).val(item.value); 
       }); 
}); 

:

{"op": "UPDATE", "id": "7","name": "Joe Public","note": "Dennis likes his coffee in the morning... He doesn't drink tea and coffee always have powdered creamer and 2 sugar's." } 

"op"는 단지 자리 표시 자이므로 메모가 존재한다면 데이터베이스를 업데이트하고 삽입하지 않으면 ...

내 문제가

, 나는 양식을 채우려면이 넣어 whwre 모른다 ... 나는 아직도이 어떻게 작동하는지 누군가가 나에게 단서를 얻을 수 있습니다 .. :)

감사를 기대했다 배우고! 데니스

+1

양식 요소 이름이 json 개체 속성과 일치합니까? – jondavidjohn

+0

예 .. 함수 내에서 창을 생성하는 경우 호출 할 수 있는지 확실하지 않습니다. – Dennis

답변

1

는 윈도우를 생성 동일한 기능의 양식을 채우기 위해 작동하지 않는 경우, onComplete를 핸들러에 전화로 추가하려고 :

onComplete : function() { 
    //All of your original code here 
    $.getJSON(/* with your JSON code here */); 
}, 

은 아마도 대화 상자가에 의해 준비가되어 있어야 그 시간, 그리고 정상적으로 양식 요소에 물건을로드 할 수 있습니다.

+0

Ahh .. 닫는 중 또는 단추를 클릭하는 것과 같은 이벤트를 발생 시켰을 때 onComplete가 있었는데도 사용할 수 있습니까? 나는 그것을 시도해 볼 것입니다. – Dennis

+0

http://fancybox.net/api에 따르면, onComplete는 "내용이 표시되면 호출됩니다." 희망이 당신을 위해 일합니다! –

+0

고마워, 잘 했어 .. :) – Dennis

관련 문제