Pez*_*lio 10 javascript typeahead coffeescript twitter-bootstrap
我正在使用Twitter Bootstrap typeahead库的这个分支,它允许异步数据源以及onselect事件.到目前为止,它对我来说非常好用,但是当用户选中该字段时(即没有主动选择下拉条目),会激活onselect事件(在我的情况下,将用户重定向到另一个页面).如果用户没有点击,有什么方法可以阻止onselect事件被触发?这是我到目前为止所得到的(在CoffeeScript中):
$(document).ready ->
$('#inspection_name').typeahead(
source: (typeahead, query) ->
$.ajax(
url: "/inspections/search.json?name="+query
success: (data) =>
return_list = []
$(data.results.inspections).each ->
return_list.push("<span data-url='" + this.uri + "/edit'>" + this.name + ", " + this.town + "</span>")
typeahead.process(return_list)
)
onselect: (obj) =>
window.location.href = $(obj).attr("data-url")
)
Run Code Online (Sandbox Code Playgroud)
对于默认的Bootstrap,这将起作用:
$.fn.typeahead.Constructor.prototype.render = function (items) {
var that = this;
items = $(items).map(function (i, item) {
i = $(that.options.item).attr('data-value', item);
i.find('a').html(that.highlighter(item));
return i[0];
});
this.$menu.html(items);
return this;
};
Run Code Online (Sandbox Code Playgroud)
在包括bootstrap之后的某个地方.(分钟)js
归档时间: |
|
查看次数: |
9512 次 |
最近记录: |