Javascript 用json填充模态表单

Javascript 用json填充模态表单,javascript,javascript-events,jquery,getjson,Javascript,Javascript Events,Jquery,Getjson,我创建了一个模态形式,如下所示: function addeditNote(rowID,callback) { var ret; jQuery.fancybox({ modal : true, overlayOpacity : 0.25, content : "<div class=\"contentbox modal-window modal-400\"><div

我创建了一个模态形式,如下所示:

    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);
            }
        });
}
返回:

{"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”只是一个占位符,所以我知道如果有便笺存在,我将更新数据库,如果没有,我将插入

我的问题是,我不知道该怎么填写表格。。我还在学习,所以我希望有人能给我一个如何工作的线索:)

谢谢!
Dennis

如果在创建窗口的同一函数中填充表单不起作用,请尝试将其作为调用添加到onComplete处理程序中:

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

此时对话框应该准备好了,您可以像平常一样将内容加载到表单元素中。

如果在创建窗口的同一函数中填充表单不起作用,请尝试将其作为调用添加到onComplete处理程序中:

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

大概到那时对话框应该准备好了,您可以像往常一样将内容加载到表单元素中。

表单元素名称与json对象属性匹配吗?是的。。我不确定是否可以从生成窗口的函数中调用if,尽管表单元素名称与json对象属性匹配吗?是。。我不确定是否可以在生成窗口的函数中调用if,尽管。。我认为onComplete是在我触发关闭或按钮单击等事件时发生的?我将尝试一下。根据,一旦内容显示,将调用onComplete。希望这对您有用!啊。。我认为onComplete是在我触发关闭或按钮单击等事件时发生的?我将尝试一下。根据,一旦内容显示,将调用onComplete。希望这对您有用!