jquery autocomplete无法读取属性'替换'未定义的

时间:2016-02-29 14:15:37

标签: javascript jquery jquery-ui frontend jquery-autocomplete

$('#tags').autocomplete({
    params: {search_type:$('#search-type').val()},
    minChars: 2,
    appendTo: $(".cash-collection-select"),
    serviceUrl: '/admin/journals/search_roles',
    onSelect: function (suggestion) {
      $("#q").val(suggestion.data);
      console.log(suggestion.data)
      alert("You selected: ' + suggestion.value + ', ' + suggestion.data")
    },
    onSearchStart: function(query) {
    console.log("query: "+query)
    },
    onSearchComplete: function (query, suggestions) {
      console.log(suggestions.data)
    }
  });

我收到错误无法读取属性'替换'未定义的。我对rails行动的回应是以json格式出现的

suggestions = User.where("email LIKE ?","#{params[:query]}%")
    message = {:query => "Unit", :suggestions => suggestions}
    render :json => message

这是我的输入#tags

<input class="search-emails" type="email" id="tags" placeholder="Search by email.." />

1 个答案:

答案 0 :(得分:0)

这是在评论中放置了很长时间,想到将其移至答案。

我从rails动作获得的数据是一个模型对象数组,我将其更改为ruby数组,现在可以正常工作了。