引导预先输入url/redirect


        $(function(){
        var orthoObjs = {};
        var orthoNames = [];

        var throttledRequest = _.debounce(function(query, process){
            $.ajax({
                url: 'json/ortho4.json'
                ,cache: false
                ,success: function(data){

                orthoObjs = {};
                orthoNames = [];

                _.each( data, function(item, ix, list){

                orthoNames.push( item.searchPhr );

                        orthoObjs[ item.searchPhr ] = item;
                    });

                    process( orthoNames );
                }
            });
        }, 300);

        $(".typeahead").typeahead({
            source: function ( query, process ) {

                throttledRequest( query, process );
            }
        ,updater: function (item) {
        var url = "orthoObjs[item.searchUrl]";
        window.location = url;

让重定向工作的最好方法是什么?我见过类似的问题,但不能得到这个工作。关于提前打字的文档不是很好。我对每个函数都使用下划线。js。只是想要一个简单的搜索查询,当用户选择重定向。

我实际上让这个工作。我得到了一点帮助……但就是这样。有JSON文件..

[
   { "id":1,  "searchUrl":"invisalign.html", "name":"invisalign" }
    ,{ "id":2, "searchUrl":"invisalign.html", "name":"invisalign teen"  }
    ,{ "id":3, "searchUrl":"clearbraces.html", "name":"clear braces"  }
]

HTML代码....

这里有很多好东西…http://fusiongrokker.com/post/heavily-customizing-a-bootstrap-typeahead

和搜索代码..

<form method="post" id="myForm" class="navbar-search pull-left">  
      <input 
            type="text"
            class="search-query typeahead"
            placeholder="Search Our Website"
            autocomplete="off"
            data-provide="typeahead"
            />
            <i class="fa-icon-search icon-black"></i>  
</form> </li>
 $(function(){
      var bondObjs = {};
      var bondNames = [];
      $(".typeahead").typeahead({
        source: function ( query, process ) {
          //get the data to populate the typeahead (plus an id value)
          $.ajax({
            url: '/json/bonds.json'
            ,cache: false
            ,success: function(data){
              bondObjs = {};
              bondNames = [];

              _.each( data, function(item, ix, list){

                bondNames.push( item.name );

                bondObjs[ item.name ] = item.searchUrl;
              });

              process( bondNames );
            }
          });
        }
        , updater: function ( selectedName ) {
          window.location.href =bondObjs[ selectedName ];
        }
      });
    });
  </script>

最新更新