문제

I'm looking into using the jQuery UI autocomplete widget to implement user lookup by first or last name. It looks like by default autocomplete looks up words by character sequence no matter its occurrence in a word. So if you have data such as: javascript, asp, haskell and you type in 'as' you will get all three. I would like it to only match beginning of the word. So in above example you get only 'asp'. Is there a way to configure the autocomplete widget to do this?

Ultimately it would be even better to match by beginning of first or last name like it is in Gmail.

Note: I'm trying to figure out a way to do this using the jQuery UI widget specifically. Since I'm already using jQuery UI in my project, I'm planning to stick with it and try not adding additional libraries to my web application.

도움이 되었습니까?

해결책

아니오.프로세스가 다른 가상 주소 지정 공간에서 실행됩니다.다른 프로세스가 할당 한 메모리 공간을 읽을 수 있으면 심각한 보안 취약점이었을 것입니다.

편집 : 원래 프로세스에서 WebBrowserControl과 같은 것을 사용하는 것을 고려하십시오.그런 식으로 당신은 냉담한 페이지를 쉽게 검색 할 수 있습니다.

다른 팁

I use the autocomplete from devbridge. http://www.devbridge.com/projects/autocomplete/jquery/

It matches on the beginning characters, only.

alt text

As far as matching based on first name or last name, you'd just have to supply a lookup list with the first and last name.

Example usage:

  var wordlist = [
      'January', 'February', 'March', 'April', 'May', 'June',
      'July', 'August', 'September', 'October', 'November',
      'December' ]; 

      var acOptions = {
          minChars:2,
          delimiter: /(,|;)\s*/, // regex or character
          maxHeight:400,
          width:300,
          zIndex: 9999,
          deferRequestBy: 10, // miliseconds

          // callback function:
          onSelect: function(value, data){
              //$('#input1').autocomplete(acOptions);
              if (typeof data == "undefined") {
                  alert('You selected: ' + value );
              }else {
                  alert('You selected: ' + value + ', ' + data);
              }
          },

          // local autosuggest options:
          lookup: wordlist
      };

The lookup option that you pass to initialize the autocomplete control can be a list, or an object. The above showed a simple list. If you want some data attached to the suggestions that get returned, then make the lookup option an object, like this:

var lookuplist = {
    suggestions:   [ "Jan", "Feb", "Mar", "Apr", "May" ],
    data :         [ 31, 28, 31, 30, 31, ]
};

thx cheeso for intrducing jsbin.com,

i extended your code to support first- and lastname matches, too.

  $("#input1").autocomplete({
      source: function(req, responseFn) {
          addMessage("search on: '" + req.term + "'<br/>");

          var matches = new Array();
          var needle = req.term.toLowerCase();

          var len = wordlist.length;
          for(i = 0; i < len; ++i)
          {
              var haystack = wordlist[i].toLowerCase();
              if(haystack.indexOf(needle) == 0 ||
                 haystack.indexOf(" " + needle) != -1)
              {
                  matches.push(wordlist[i]);
              }
          }

          addMessage("Result: " + matches.length + " items<br/>");
          responseFn( matches );
      }
  });

demo: http://jsbin.com/ufimu3/

type 'an' or 're'

여기에 있습니다.이 코드를 사용하여 특정 디렉토리에 모든 org 파일을 나열합니다.모든 파일을 나열하려면 소스의 후보 변압기 행을 제거하고 eMagician / helm-ct-is-org 파일을 제거하십시오.

소스 / 변수 / 함수의 이름을 바꾸려고 할 것입니다.;)

편집 : 고정, helm-cmd-t 에서 엿보기 덕분에

참고 : 이것은 헬름 소스를 만드는 나의 첫 번째 실제 균열이며,이 구현은 흡입 할 것입니다.또한 내 문제를 구체적으로 해결합니다 (직접 모든 Org 파일을 직접 찾으십시오).

(defvar emagician/helm-c-source-files
  `((name  . "Find Emagician Files")
    (header-name . (lambda (_)))
    (candidates . ,(lambda () 
                    (when (file-accessible-directory-p emagician-dir)
                      (directory-files emagician-dir t))))
    (match helm-c-match-on-file-name helm-c-match-on-directory-name)
    (keymap . ,helm-generic-files-map)
    (candidate-transformer . emagician/helm-ct-is-org-file)
    (help-message . helm-generic-file-help-message)
    (mode-line . ,helm-generic-file-mode-line-string)
    (type . file)))

(defun emagician/helm-ct-is-org-file (candidates)
  (remove-if-not (lambda (c)
                   (and (string= (substring c -4) ".org")
                        (not (string= (substring (file-name-nondirectory c) 0 2) ".#"))))
                 candidates))


(defun emagician/helm-emagician-dir () 
  "List all the org files in the Emagician dir"
  (interactive)
  (helm :sources emagician/helm-c-source-files
        :candidate-number-limit 40
        :buffer "*emagician-|-+-|-files*"))

(global-set-key (kbd "S-<f3>") 'emagician/helm-emagician-dir)
.

There’s another jQuery autocomplete plug-in that optionally searches just at the start of each item (the option is matchContains=false, I think that’s the default too).

Given the absence of such an option in the jQuery UI plugin, I’m guessing you’ll either have to use a different plugin, or rewrite the one you’re using now.

Where are you getting the data to populate the autocomplete? Is it from a database? If so, you can do what you want in your query and only return results that match the beginning of each word (first/last name)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top