TokenInput不能很好地处理加号

时间:2012-05-07 14:56:07

标签: jquery

DEMO

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);  
// ---------------------

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

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

3 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分: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才能获得所需的输出。

答案 2 :(得分:0)

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