2017-02-02 70 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',” –