-1

演示

HTML:

<link rel="stylesheet" href="token-input-facebook.css" />
<script src="jquery.tokeninput.js"></script>
<br/><label for="ExpFilter">Expl:</label><br/>
<input type="text"  id="ExpFilter" style="width:100px"/>        

jQuery:

var Code_Expl = [
{ id: 0, name:"+ DESIGNATED CONTRACTING STATES:"},
{ id: 1, name:"+ EXTENSION OF THE EUROPEAN PATENT TO"},
{ id: 2, name:"+ REQUEST FOR EXAMINATION FILED"},
{ id: 3, name:"+ PAYMENT OF DESIGNATION FEES"},
{ id: 4, name:"+ FIRST EXAMINATION REPORT"},
{ id: 5, name:"- LAPSED IN A CONTRACTI...FROM NAT. OFFICE TO EPO"},
{ id: 6, name:"+ EUROPEAN PATENT GRANTED"},
{ id: 7, name:"+ ENTRY IN THE NATIONAL PHASE"},
{ id: 8, name:"BE: CHANGE OF HOLDER'S NAME"},
{ id: 9, name:"CORRESPONDS TO:"},
{ id:10, name:"+ EUROPEAN PATENTS GRANTED DESIGNATING IRELAND"},
{ id:11, name:"- PATENT CEASED"},
{ id:12, name:"- FR: TRANSLATION NOT FILED"},
{ id:13, name:"+ NO OPPOSITION FILED"},
{ id:14, name:"- PATENT LAPSED"},
{ id:15, name:"+ POSTGRANT: ANNUAL FEES PAID TO NATIONAL OFFICE"},
{ id:16, name:"- BE: LAPSED"},
{ id:17, name:"- GB: EUROPEAN PATENT C...-PAYMENT OF RENEWAL FEE"}
];

作品:

var query = "+ DE";  
var results = $.grep(Code_Expl, function (row) {
  return row.name.toLowerCase().indexOf(query.toLowerCase()) > -1;
});
console.log(results);  
// ---------------------

WORKS,但不适用于以 PLUS 开头的内容 - 为什么?我使用上面相同的 grep 似乎是填充函数失败但我不明白为什么

$(document).ready(function() {
  $("#ExpFilter").tokenInput(Code_Expl,{theme: "facebook"});
});    
4

3 回答 3

2

六个月前在 github 上的一次提交中修复了这个问题:

https://github.com/loopj/jquery-tokeninput/pull/314

只需从github而不是从网站下载master,就可以了。在我自己的网站上遇到了与“C++”类别相同的问题。

于 2012-11-19T14:22:33.027 回答
1

我必须明白,问题出在这两个函数的正则表达式中。

    function highlight_term(value, term) {
        return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<b>$1</b>");
    }

    function find_value_and_highlight_term(template, value, term) {
        return template.replace(new RegExp("(?![^&;]+;)(?!<[^<>]+)(" + value + ")(?![^<>]*>)(?![^&;]+;)", "g"), highlight_term(value, term));
    }

您必须修改此 regEx 以获得所需的输出。

于 2012-05-07T15:54:03.520 回答
0

我遇到了同样的问题。只需将 + 字符替换为 + unicode :)

于 2012-11-15T14:31:13.800 回答