2017-02-02 118 views
-1

我正在使用Select2 js庫,但我不能將鏈接放入選擇選項。 這裏是我的JSON結構Select2轉到href鏈接

[{id: 1, title: "Foo", slug: "foo"}] 

而我選擇2腳本

$(".search-box").select2({ 
    placeholder: "Enter...", 
    ajax: { 
     url: window.location.href + '/search', 
     dataType: 'json', 
     delay: 250, 
     data: function (params) { 
      return { 
       q: params.term // search term 
      }; 
     }, 
     processResults: function (data) { 
      // parse the results into the format expected by Select2. 
      // since we are using custom formatting functions we do not need to 
      // alter the remote JSON data 
      return { 
       results: $.map(data, function (item) { 
        return { 
         text: item.title, 
         id: item.id 
        } 
       }) 
      }; 
     }, 
     cache: true 
    }, 
    minimumInputLength: 2, 
    maximumSelectionLength: 6 
}); 

我希望當我鍵入並單擊希望瀏覽器去後的地址選擇適當選項的標題(鏈接)是

因此,任何幫助plzzz

回答

1

你不能把window.location.href在URL中。而是使用適當的頁面URL路徑。

window.location.href主要用於頁面重定向。

+0

但是...我用它,它工作正常,並且問題不在線「url:window.location.href +'/ search',」 –