【问题标题】:no view in autocomplete plugin of jquery uijquery ui的自动完成插件中没有视图
【发布时间】:2014-03-17 11:56:26
【问题描述】:

我正在数据库中搜索一些项目并得到一个 json 响应。

但我不知道,我的自动完成功能的哪一部分不起作用 当我制作 console.log(item) 时,我从 item 中得到了这个输出:

Array
(
[0] => Array
    (
        [objektnummer] => 14720
        [anschrift1] => Frau
        [anschrift2] => xxxx
        [strasse] => Bucxxx
        [plz] => 8xxx
        [ort] => Pxxxx
        [projektstatus] => 3
        [erstellungsdatum] => 2014-03-16 12:15:12
        [fertigstellungsdatum] => 2014-03-14
    )

[1] => Array
    (
        [objektnummer] => 14778
        [anschrift1] => 

        [anschrift2] => MFH + TG
        [strasse] => Gedxxx
        [plz] => 8xxx
        [ort] => Ascxxx
        [projektstatus] => 1
        [erstellungsdatum] => 2014-02-05 12:15:12
        [fertigstellungsdatum] => 2014-01-02
    )

)

我的错误在哪里?来自 php 搜索的响应是正确的。因此,带有 url 的 ajax 也可以正常工作

$( "#qObject" ).autocomplete({
    source: function( request, response ){
        $.ajax({
            url: $( "#spanqObject" ).data( "url" )
        }).success(function(item){
            console.log(item);
            response(function(item) {
                return {
                    label: item.anschrift2,
                    value: item.anschrift2
                }
            });

        }).error(function(){
            console.log("Mist");
        });
    },
    minLength: 2,
    select: function( event, ui ) {
        log( ui.item ?
            "Selected: " + ui.item.anschrift2 + " aka " + ui.item.objektnummer :
            "Nothing selected, input was " + this.value );
    }
});

【问题讨论】:

  • 如果可以的话,创建一个小提琴。
  • 我不明白你的问题是什么。请更具体。
  • 我没有得到包含搜索结果的列表
  • console.log 告诉你什么?

标签: jquery jquery-ui autocomplete


【解决方案1】:

仍然不确定您要做什么。我想您正在尝试使用自动完成功能从远程位置加载数据,填充下拉列表,然后选择一个值?看起来你正在使用 PHP。您是否尝试过PHP Autocomplete

<?php
$pac = new C_PhpAutocomplete('remote_data');
$pac -> load_remote_data('http://example.com/sample_remote_data.php');
$pac -> display();
?>
<input id="remote_data" type="hidden" />

sample_remote_data.php 应该包含带有 json 编码的数据数组。

<?php
echo json_encode(Array
(
[0] => Array
    (
        [objektnummer] => 14720
        [anschrift1] => Frau
        [anschrift2] => xxxx
        [strasse] => Bucxxx
        [plz] => 8xxx
        [ort] => Pxxxx
        [projektstatus] => 3
        [erstellungsdatum] => 2014-03-16 12:15:12
        [fertigstellungsdatum] => 2014-03-14
    )

[1] => Array
    (
        [objektnummer] => 14778
        [anschrift1] => 

        [anschrift2] => MFH + TG
        [strasse] => Gedxxx
        [plz] => 8xxx
        [ort] => Ascxxx
        [projektstatus] => 1
        [erstellungsdatum] => 2014-02-05 12:15:12
        [fertigstellungsdatum] => 2014-01-02
    )

));
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多