0

我正在处理 jquery 多个自动完成功能,但是,当我输入一些内容时,所有项目都会发布而不是匹配的项目。我的 Javascript 是

$('.tags').bind("keydown", function(event) {
if (event.keyCode === $.ui.keyCode.TAB && $(this).data("autocomplete").menu.active) {
    event.preventDefault();
    }
}).autocomplete({
    source : function(request, response) {
        $.getJSON($.cookie('base_url') + "js/getaddressbook.php", {
            term : extractLast(request.term)
        }, response);
    },
    search : function() {
        var term = extractLast(this.value);
        if (term.length < 2) {
            return false;
        }
    },

    focus : function() {
        return false;
    },
    select : function(event, ui) {
        var terms = split(this.value);
        terms.pop();
        terms.push(ui.item.value);
        terms.push("");
        this.value = terms.join("; ");
        return false;
    }
});

js/getaddressbook.php 返回

["gunjan.soni","askhr","saurabh.burman","Aditi.Nehra","ithelpdesk","shipra.kwatra","gagandeep.manchanda"]

不知道我哪里错了。

下面是快照的样子

http://i.stack.imgur.com/SmRjX.png

请帮忙!

我的 JS 控制器有这个功能

Public function getaddressbook() {
        $this -> load -> model('common_model');
        $data = $this -> common_model -> addressbook();
        echo json_encode($data);
    }

而common_model有这个功能

Public function addressbook()
    {
        $this -> db -> select('emailid');
        $this -> db ->where('emailid <>','');
        $result = $this -> db -> get('addressbook');
        if ($result -> num_rows() > 0)
        {
            foreach ($result->result() as $row)
            {
                $data[] = $row -> emailid;
            }
            return ($data);
        }
        else
        {
            return FALSE;
        }
    }
4

1 回答 1

2

You are not passing the term anywhere in your controller.

And of course using that term to query your database for example:

$this->db->like('column_name', $term);  

For your code, it could be:

Public function getaddressbook() {
        $this -> load -> model('common_model');
        $term = $this->input->get('term');
        $data = $this->common_model->addressbook($term);
        echo json_encode($data);
    }

Public function addressbook($term)
    {
        $this -> db -> select('emailid');
        $this -> db ->where('emailid <>','');
        $this->db->like('column_name', $term);
        $result = $this -> db -> get('addressbook');
        if ($result -> num_rows() > 0)
        {
            foreach ($result->result() as $row)
            {
                $data[] = $row -> emailid;
            }
            return ($data);
        }
        else
        {
            return FALSE;
        }
    }
于 2013-01-22T20:15:28.437 回答