2010-12-31 5 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文字列を取得します:

{"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." } 

を:返す

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

私は知っているので、私はデータベースを更新しているし、私はそれを挿入している場合は、私が知っているので、 "op"ちょうどプレースホルダー..

私の問題は、私は、フォームを移入するためにこれを入れてwhwreかわからない、です..私はまだので、誰かが私にこれがどのように機能するかの手掛かりを与えることができる期待していた勉強.. :)

感謝を! デニス

+1

あなたのフォームの要素名はjsonオブジェクトのプロパティと一致しますか? – jondavidjohn

+0

はい..私は関数内から私がウィンドウを生成しているかどうかを呼び出すことができるかどうか分かりません – Dennis

答えて

1

それはonCompleteのハンドラ内で呼び出しとして、それを追加してみてください、ウィンドウを作成し、同じ機能でフォームを移入するために動作しない場合:

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

おそらくダイアログがで準備する必要がありますその時、フォーム要素に物事を通常どおりに読み込むことができます。

+0

ああ..私はonCompleteが閉じるかボタンのクリックなどのイベントを発生させたのですが?私はそれを試してみましょう.. – Dennis

+0

http://fancybox.net/apiによると、onComplete "コンテンツが表示されたら呼び出されます。"あなたのために働くことを願っています! –

+0

おかげで、うまく働いた.. :) – Dennis

関連する問題