【问题标题】:Typeahead not work in dialog edit of jqGridTypeahead 在 jqGrid 的对话框编辑中不起作用
【发布时间】:2015-08-23 03:48:58
【问题描述】:

我尝试从服务器响应 json,例如 the official demo

但是没有显示下拉建议。

谁能告诉我我错过了什么? 我只更改了演示代码中的 url:

{
    label: 'Ship Name2',
    name: 'ShipName2',
    width: 150,
    editable: true,
    edittype: "text",
    editoptions: {
        dataInit: function (element) {
           $(element).attr("autocomplete","off").typeahead({ 
               appendTo : "body",
                source: function(query, proxy) {
                    $.ajax({
                        url: 'mysite',
                        dataType: "jsonp",
                        data: {term: query},
                        success : proxy
                    });
                }
           });
        }
    }
}, {
    label: 'Ship Name',
    name: 'ShipName',
    width: 150,
    editable: true,
    edittype: "text",
    editoptions: {
        dataInit: function (element) {
           $(element).attr("autocomplete","off").typeahead({ 
               appendTo : "body",
                source: function(query, proxy) {
                    $.ajax({
                        url: 'http://trirand.com/blog/phpjqgrid/examples/jsonp/autocompletepbs.php?callback=?&acelem=ShipName',
                        dataType: "jsonp",
                        data: {term: query},
                        success : proxy
                    });
                }
           });
        }
    }
}

附:我的 servlet 返回与 demo 完全相同的 json。

谢谢!!

编辑1:如果我想在这个演示中使用预输入,响应不应该只是一个json吗?

如果我在演示中执行url,我会得到以下 javascript 而不是 json:

<script type='text/javascript'>
    jQuery(document).ready(function() {
        if(jQuery.ui) { 
            if(jQuery.ui.autocomplete){
                jQuery('ShipName').autocomplete({
                    "appendTo":"body",
                    "disabled":false,
                    "delay":300,
                    "minLength":1,
                    "source":function (request, response){
                        request.acelem = 'ShipName';
                        request.oper = 'autocmpl';
                        $.ajax({
                            url: "autocompletep.php",
                            dataType: "json",
                            data: request,
                            type: "GET",
                            error: function(res, status) {
                                alert(res.status+" : "+res.statusText+". Status: "+status);
                            },
                            success: function( data ) {
                                response( data );
                            }
                        });
                }});
                jQuery('ShipName').autocomplete('widget').css('font-size','11px');
                jQuery('ShipName').autocomplete('widget').css('z-index','1000');
            } 
        }
    });
</script>

谁能告诉我为什么?

【问题讨论】:

    标签: jqgrid typeahead


    【解决方案1】:

    演示使用 JSONP 获取数据。如果您在本地站点,则需要删除 calcback=?参数。

    最基本的睾丸不是在typeahead中使用ajax,而是使用数组作为数据源。这样你就可以确保这项工作是正确的

    【讨论】:

    • 感谢您的回复。但这仍然行不通。有没有可能我不应该只返回一个 json?
    • 响应可以是任何数据类型。您需要阅读 typeahead 的文档才能对其进行配置。您可以使用演示中的链接来确保有响应。
    猜你喜欢
    • 1970-01-01
    • 2013-02-05
    • 2014-11-09
    • 2011-04-18
    • 2011-04-26
    • 1970-01-01
    • 2014-08-14
    • 2011-09-23
    • 1970-01-01
    相关资源
    最近更新 更多