Twitter TypeAhead 在下拉列表中创建额外链接

twitter typeahead create extra link in dropdown

本文关键字:链接 创建 TypeAhead 下拉列表 Twitter      更新时间:2023-09-26

我想覆盖Twitter的默认行为。

当显示建议时,我希望能够添加<a><button>标签,以便在单击该特定按钮时,它不会执行典型的下拉行提交。

我知道如何进行模板化以在模板中呈现按钮/链接,但无法弄清楚如何将整行单击覆盖为单个按钮单击。

templates: {
  header: '<h3 class="search-set">asdf</h3>',
  suggestion: function(context) {
    return Mustache.render(template, context);
  }
}

提前谢谢。

好吧,您可以使用由 typeahead 在选择中触发的自定义事件。

如果你真的需要一个按钮,那更像是一个小胡子问题。一种解决方案是通过jQuery将onClick处理程序添加到生成的html中,例如

suggestion: function(context) {
  var html = Mustache.render(template, context);
  $('button', html).on('click', function(){alter('something')});
  return html;
}