<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] > [github](https://github.com/krisk/fuse/) > [home](https://fusejs.io/) ## 安裝 `npm install fuse.js` ## 概述 Fuse.js 是一個輕量級的模糊搜索,在 JavaScript 中,零依賴。 ### 瀏覽器兼容性 Fuse.js 支持所有[符合 ES5 的](http://kangax.github.io/compat-table/es5/)瀏覽器(不支持 IE8 及以下版本) ## 完整 demo ``` // html <input type="text" id="search"> <ul id="content"> </ul> // js <script src="https://cdn.bootcss.com/fuse.js/3.4.5/fuse.min.js"></script> <script> var list=[ { title: "Old Man's War", author: { firstName: "John", lastName: "Scalzi" } }, { title: "The Lock Artist", author: { firstName: "Steve", lastName: "Hamilton" } }, ]; var options = { shouldSort: true, threshold: 0.1, location: 0, distance: 100, maxPatternLength: 32, minMatchCharLength: 3, keys: [ "title", "author.firstName" ] }; var fuse = new Fuse(list, options); // "list" is the item array var content = document.querySelector("#content"); document.querySelector("#search").addEventListener("input",function (item) { var result = fuse.search(item.target.value); console.log(result); var html =""; result.forEach(function (item) { html+=`<li>title : ${item.title} | firstName : ${item.author.firstName} | lastName : ${item.author.lastName} </li>`; }) content.innerHTML=html; }) </script> ``` ## 官方 demo ### 按ID搜索 搜索結果只返回 id 指定的值 ``` var books = [{ 'ISBN': 'A', 'title': "Old Man's War", 'author': 'John Scalzi' }, { 'ISBN': 'B', 'title': 'The Lock Artist', 'author': 'Steve Hamilton' }] var options = { keys: ['title', 'author'], id: 'ISBN' } var fuse = new Fuse(books, options) fuse.search('old') /**[ "A" ]*/ ``` ### 加權搜索 加權影響結果排名 ``` var books = [{ title: "Old Man's War fiction", author: 'John X', tags: ['war'] }, { title: 'Right Ho Jeeves', author: 'P.D. Mans', tags: ['fiction', 'war'] }] var options = { keys: [{ name: 'title', weight: 0.3 }, { name: 'author', weight: 0.7 }] }; var fuse = new Fuse(books, options) fuse.search('Man') /** [{ "title": "Right Ho Jeeves", "author": "P.D. Mans", "tags": ["fiction", "war"] }, { "title": "Old Man's War fiction", "author": "John X", "tags": ["war"] }] */ ```` ### 在字符串數組中搜索 數組中的值可以進行搜索 ``` var books = [{ 'title': "Old Man's War", 'author': 'John Scalzi', 'tags': ['fiction'] }, { 'title': 'The Lock Artist', 'author': 'Steve', 'tags': ['thriller'] }] var options = { keys: ['author', 'tags'] }; var fuse = new Fuse(books, options) fuse.search('tion') /**[{ "title": "Old Man's War", "author": "John Scalzi", "tags": ["fiction"] }]*/ ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看