动态本地源上的jqgrid自动完成

时间:2013-05-21 18:38:41

标签: jqgrid autocomplete

我尝试使用自动填充进行表单编辑..每次用户打开编辑表单时,其来源都不同

打开编辑表单时:

beforeShowForm: function(frm) { 
    var id = grid.jqGrid('getGridParam','selrow');
    if (id) {
        var ret = grid.jqGrid('getRowData',id);
        AccCode = ret.szAccCode;
    };
    $.post("url_getchildren", { szAccCode: AccCode}).
        done(function(data) {
                lschildcode=data;
        });
},

我有来自服务器的管理结果, 但我不能把它发送到网格。

colModel

{name:'szAccParentCode',index:'szAccParentCode', editable:true, edittype:'text',
    editoptions : {
        dataInit: function(elem){
            $(elem).focus(function(){
                this.select();
            }),
            $(elem).autocomplete({
                source:lschildcode
            })
        }
    }
},

为什么我无法将lschildcode传递给自动填充源?每当我在框中输入时,自动完成功能都会将术语发送到服务器。

TIA

1 个答案:

答案 0 :(得分:0)

我认为在执行dataInit autocomplete之前,done(以及$.post)将被称为

要解决此问题,您可以在$("#szAccParentCode").autocomplete({source:lschildcode})内调用done

另一种方式:可以使用URL作为source的值。 URL可以包含一些其他参数。如果您需要使用HTTP POST,可以将source声明为函数,并在responsesuccess实现的done内调用source参数(回调函数)。只需查看the remote with caching示例中source的实现并检查代码(单击“查看源代码”)或检查$.ajax用法附近的jQuery UI自动填充的源代码(请参阅{{ 3}})。