jQuery自动完成ajax类型错误

jQuery自动完成ajax类型错误,jquery,json,autocomplete,Jquery,Json,Autocomplete,不知道为什么在尝试使用ajax源代码实现自动完成时会继续出现此错误 "Uncaught TypeError: Cannot read property 'length' of undefined" 这是我坐快车的路线 exports.findAllIrds = function(req, res) { var name = req.query["value"]; db.collection('employees', function(err, collection) {

不知道为什么在尝试使用ajax源代码实现自动完成时会继续出现此错误

"Uncaught TypeError: Cannot read property 'length' of undefined" 
这是我坐快车的路线

exports.findAllIrds = function(req, res) {
    var name = req.query["value"];
    db.collection('employees', function(err, collection) {
        if (name) {
            collection.find({
                "value": new RegExp(name, "i")
            }, {
                value: 1,
                data: 1,
                _id: 0
            }).toArray(function(err, items) {
                res.jsonp(items);
                //console.log(req.query);
                //console.log(items);
            });
        } else {
            collection.find().toArray(function(err, items) {
                res.jsonp(items);
                console.log(req.query);
            });
        }
    });
};
如果我浏览到/receiversjson,我会得到预期的所有json,当我浏览/receiversjson?value=293589324时,我会得到

[{“值”:“2935893244”,“数据”:“D33HL3RH31191”}]
如预期

然而,当我尝试使用以下代码实现jquery自动完成时,我得到了一个错误

$('.item-name textarea').autocomplete({
    serviceUrl: '/receiversjson',
    paramName: 'value',
    autoSelectFirst: true,
    onSelect: function(suggestion) {
        alert('You selected: ' + suggestion.value + ', ' + suggestion.data);
    }
});  



Uncaught TypeError: Cannot read property 'length' of undefined
在chrome开发者工具网络选项卡中,我看到“receiversjson?value=293589324”,当我点击它时,它会打开一个包含我的json的页面

[{
    "value": "2935893244",
    "data": "D33HL3RH311911"
}]
我错过了什么或做错了什么


我的问题是json响应没有包含“建议”:我的输出是这样的

[
  {
    "value": "1999458647",
    "data": "A10GA8CW330293"
  }
]
jqueryautocomplete正在寻找这个

{
  "suggestions": [
    {
      "value": "1999458647",
      "data": "A10GA8CW330293"
    }
  ]
}
我现在用它来做这个

exports.findAllIrds = function(req, res) {
    var name = req.query["value"];
    db.collection('employees', function(err, collection) {
        if (name) {
            collection.find({"value": new RegExp(name, "i")},{value:1,data:1,_id:0}).toArray(function(err, items) {
                var myobj = {};
                var suggestions = 'suggestions';
                myobj[suggestions] = items;
                res.jsonp(myobj);
            });
        } else {
            collection.find().toArray(function(err, items) {
                res.jsonp(items);
                console.log(req.query);
            });
        }
    });
};

你的HTML是什么样子的?只是一个猜测,但是它不能找到你的文本区域吗?你可能有一个坏的jquesry选择器?我不再在我的电脑前发布HTML了。但我相信选择器是正确的,因为当我在文本区域中键入时会发生错误。哦,我想确定错误发生的时间。。。我不确定你是否可以在文本区域中使用自动完成功能,你可以尝试将它附加到文本或搜索类型的输入中吗?在阅读你的评论并进行谷歌搜索后,我认为你对我的文本区域问题的看法是对的。我会试试你的建议,并跟进我的发现。ThanksI能够让autocomplete在文本区工作。。。我确实看到了以下文档,其中建议在使用json时使用选项“dataType:jsonp”。