0

Twitterのブートストラップタイプヘッドを使用しています。

 $(document).ready(function() {
        $("#searchfield").typeahead({
            minLength: 3,
            source: ["type1", "type2", "dtype3", "dtype4"]
        });
    });

inputタグ(「#searchfield」)にフォーカスを当てたときに、空でもドロップダウン(提案ドロップダウン)にすべてのソースを表示したい。つまり、文字を入力しなかったときにすべてのソースを表示したいということです。文字を入力した場合は、関連するデータを表示する必要があります (タイプヘッドの通常の機能です)。

また

いくつかのリンクをクリックすると。ドロップダウンは、指定されたすべてのソースを提供する必要があります。例:

<a href="#someId">Click here to populate typehead in #searchfield input tag </a>
<input type="text" id="searchfield">

リンクをクリックすると、入力フィールドは、指定されたすべてのソースをドロップダウンに入力する必要があります( type1, type2, dtype3,dtype4)

4

1 に答える 1

0

このようにプラグインで次のメソッドを変更しました

, lookup: function (event) {
      var that = this
        , items
        , q

      this.query = this.$element.val()

    //console.log(this.query);
    //alert("this.query"+ this.query);

      if (!this.query) {
         return this.shown ? this.hide() : this
      }

      items = $.grep(this.source, function (item) {
       if this.query == "*"
          return item
       else
          return that.matcher(item)

      })

        //console.log("==items=="+items.length);
        //console.log(items);

      items = this.sorter(items)

       if (!items.length) {
        return this.shown ? this.hide() : this
      }

      return this.render(items.slice(0, this.options.items)).show()
    }

そして、クリックイベントをアンカータグにバインドしました(<a id="someID" ......

jQuery('#someID').click(function(){
     var $input = $("#seachfield");
     //add something to ensure the menu will be shown
      $input.val('*');
      $input.typeahead('lookup');
      $input.val('');


});

これが他の人に役立つことを願っています。

于 2013-01-27T07:59:32.160 に答える