乱世@小熊 2016-12-02 23:02 采纳率: 75%
浏览 67

Typeahead.js无法获取产品ID?

我被这个问题困扰好久了......我的问题是我无法检索所选产品的id,一直提示值=0。我的代码:

$("#recherche").typeahead({
    onSelect: function(item) {
        alert(item.value); // = 0
    },
    ajax: {
        url: "/personne/autocompletation",
        displayField: "nomComplet",
        triggerLength: 1,
        method: "POST",
        dataType: "JSON",
        preDispatch: function (query) {
            return {
                query: query
            }
        }
    },
});

HTML代码:

<li class="active" data-value="0"><a href="#"><strong>C</strong>alloway</a></li>
  • 写回答

1条回答 默认 最新

  • weixin_33725515 2016-12-04 16:39
    关注

    Try this

    $("#recherche").typeahead({
        source: function(query, process){
         $.ajax({
            url: "/personne/autocompletation",
            displayField: "nomComplet",
            triggerLength: 1,
            method: "POST",
            dataType: "JSON",
            success: function (data) {
               console.log(data);
            }
        });
        }
    

    });

    评论

报告相同问题?