2

selected.jsを使用して国際文字を検索するための修正を見つけた人はいますか?

たとえば、次のオプションを含む複数選択フィールドがある場合: - フランスのシャトー - イギリスのシャトー

そして「チャ」を探す

英語のみが表示されます。

4

2 に答える 2

5

答えるのに遅すぎないかどうかはわかりませんが、おそらく他の誰かを助けることができます.

ポイントは、比較中に、入力された文字列と一致したオプション文字列から分音符号を削除することです。私の変更は、 githubからダウンロードしたバージョン 1.1.0 の jquery Chosen プラグインで動作しています。

最初に分音記号を削除する関数が必要です (winnow_results() の後に追加しました)。

// strip czech diacritics from string
AbstractChosen.prototype.strip_diacritics= function(string) {
  var 
    translationTable= [
      // input with diacritics - add your characters if necessary
      "éěÉĚřŘťŤžŽúÚůŮüÜíÍóÓáÁšŠďĎýÝčČňŇäÄĺĹľĽŕŔöÖ",
      // stripped output
      "eeEErRtTzZuUuUuUiIoOaAsSdDyYcCnNaAlLlLrRoO",
    ],
    output= '';

  // scan through whole string
  for (var i= 0; i < string.length; i++) {
    var charPosition= translationTable[0].indexOf(string[i]);
    output+= charPosition == -1 ? string[i] : translationTable[1][charPosition];
  }

  return output;
}

次に、winnow_results() 関数の適切な場所で使用します。selected.jquery.js行の参照:

315行目

searchText = this.get_search_text();
// replace with
searchText = this.strip_diacritics(this.get_search_text());

339行目

option.search_match = this.search_string_match(option.search_text, regex);
// replace with
option.search_match = this.search_string_match(this.strip_diacritics(option.search_text), regex);

最後に#345 行目

startpos = option.search_text.search(zregex);
// replace with
startpos = this.strip_diacritics(option.search_text).search(zregex);

そして、あなたは完了です:-)。

(古い DOS ゲームのエクストラ ライフ用の「savegame バイト置換」命令を書きたいと思います)

pastebin で変更されたファイル全体

2016 年 9 月 29 日: Chosen 1.6.2 で行われた変更、問題なくテストされました。

于 2014-12-19T15:56:53.907 に答える
0

Chosen がデフォルトでこれを行っているようには見えません。コードにはこのための機能はありません。

ソースコードはこちらです。文字のチェックを担当する検索機能を以下に投稿しました。この関数には、そのような近いキャラクターを処理するものは何もないため、それを作成するか、Chosen チームにその機能を要求する必要があります。これは、基本的に、アクセント付きの文字とアクセントのない文字が同じ ASCII (または Unicode) 値を持たないためです。何らかのタイプのルックアップ テーブルが必要で、文字ごとにそれを解析して「あいまいな」結果を返す必要があります。

申し訳ありませんが、これ以上お役に立てませんでした。この関数を変更する方法を見つけることができれば、これを機能させることができると確信しています。繰り返しますが、基礎となるコード値にはルックアップ テーブルまたは何かが必要です。幸運を祈ります。

編集:ルックアップテーブルは必要ないかもしれません-おそらく正規表現機能にはこれを行う組み込みの方法があります。または、検索している文字に近いものを単純に一致させることもできます。

Chosen.prototype.winnow_results = function() {
      var found, option, part, parts, regex, regexAnchor, result, result_id, results, searchText, startpos, text, zregex, _i, _j, _len, _len1, _ref;
      this.no_results_clear();
      results = 0;
      searchText = this.search_field.val() === this.default_text ? "" : $('<div/>').text($.trim(this.search_field.val())).html();
      regexAnchor = this.search_contains ? "" : "^";
      regex = new RegExp(regexAnchor + searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
      zregex = new RegExp(searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"), 'i');
      _ref = this.results_data;
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        option = _ref[_i];
        if (!option.disabled && !option.empty) {
          if (option.group) {
            $('#' + option.dom_id).css('display', 'none');
          } else if (!(this.is_multiple && option.selected)) {
            found = false;
            result_id = option.dom_id;
            result = $("#" + result_id);
            if (regex.test(option.html)) {
              found = true;
              results += 1;
            } else if (this.enable_split_word_search && (option.html.indexOf(" ") >= 0 || option.html.indexOf("[") === 0)) {
              parts = option.html.replace(/\[|\]/g, "").split(" ");
              if (parts.length) {
                for (_j = 0, _len1 = parts.length; _j < _len1; _j++) {
                  part = parts[_j];
                  if (regex.test(part)) {
                    found = true;
                    results += 1;
                  }
                }
              }
            }
            if (found) {
              if (searchText.length) {
                startpos = option.html.search(zregex);
                text = option.html.substr(0, startpos + searchText.length) + '</em>' + option.html.substr(startpos + searchText.length);
                text = text.substr(0, startpos) + '<em>' + text.substr(startpos);
              } else {
                text = option.html;
              }
              result.html(text);
              this.result_activate(result);
              if (option.group_array_index != null) {
                $("#" + this.results_data[option.group_array_index].dom_id).css('display', 'list-item');
              }
            } else {
              if (this.result_highlight && result_id === this.result_highlight.attr('id')) {
                this.result_clear_highlight();
              }
              this.result_deactivate(result);
            }
          }
        }
      }
      if (results < 1 && searchText.length) {
        return this.no_results(searchText);
      } else {
        return this.winnow_results_set_highlight();
      }
    };
于 2013-01-10T17:53:21.170 に答える