3
我正在使用select2插件,我需要使用传输函数来自己执行ajax请求,因为我需要在请求头。但是,只要我这样做,select2会正确响应结果,并按照我想要的格式显示它,但显示的结果不可选。我既不能用鼠标点击它们,也不能用箭头键导航到它们,当我用鼠标移过它们时也没有任何鼠标悬停效果。使用select2:使用传输函数时,结果不可选
下面是一些代码(我想显示的用户名的建议):
ajax: {
data: function (term, page) {
return {
Searchtext: term
};
},
transport: function(queryParams){
// Api.Ajax delivers { Ajax: *the $.ajax object*, RequestId: *some requestId* }
var req = Api.Ajax("/api/suggestion/share/" + queryParams.data.Searchtext, "POST", { UserOnly: true }, queryParams.success);
return req.Ajax;
},
// parse the results into the format expected by Select2.
results: function(resp, page) {
return {
results: resp.Data,
more: false
};
}
},
就像我说的,只要我用我自己的Ajax功能通过实现传输功能,结果在下拉列表全部显示,但不可选择。
这是一个错误,还是我做错了什么?
好吧,相关主题让我找到解决方案。必须在ajax之上设置一个id函数。看看下面的主题,看看解决方案:http://stackoverflow.com/questions/14819865/select2-ajax-method-not-selecting – thnew
这是我的问题也解决了。看到此链接: [计算器] [1] [1]:http://stackoverflow.com/questions/14193463/an-event-is-interfering-with-select2-plugins-ajax-检索结果 – MHS