ExtJS 3 Implementing the phonetic filtering of the ComboBox drop-down list

Source: Internet
Author: User

The drop-down list is a common form element that can be used instead of manual input to improve input efficiency and accuracy. But sometimes, if the drop-down list has too many options, it can cause inconvenience and reduce input efficiency.

For example, 12306 train ticket booking system, the hair station and the arrival box, select from the drop-down list is very difficult. In daily use the input text pinyin first letter (simple spelling, sequencer) in the way of optional filtering, now we try to use this method in Extjs3, ExtJS Other versions can be referenced.

To get the corresponding pinyin by the Chinese characters, the way is varied. The first is to add fields to the database to save the optional spelling, which requires the operator to manually maintain the optional spelling, perhaps not the way everyone wants.

In other words, it needs to be translated in code, either in the background code or in the foreground page. Now provides a way to handle it in the foreground. You can download a JavaScript code widget that writes kanji to pinyin. Call the function to achieve the desired purpose ( Unfortunately, there is no good way to Polyphone.

JavaScript files:http://files.cnblogs.com/cnscoo/ChinesePY.js

Refer to the Chinesepy.js file, add the project attention to the encoding format, if garbled, it can not be translated. Start writing code below:

var teststore = new Ext.data.Store ({proxy:new Ext.data.HttpProxy ({url: ' Formdemo.do?reqcode=queryareadatas '//  Background query get optional}), Reader:new Ext.data.JsonReader ({}, [{name: ' value '}, {name: ' text '}]), listeners: {load:function (PStore, option) {//load when the text of each record is translated into a simple spelling Pstore.each (function (record) {var text = record.get (' text '); var code = PINYIN.GETJP ( text);//get Chinese, call function to get corresponding simple spelling record.set (' code ', code);})}); Teststore.load ();


var Testcombo = new Ext.form.ComboBox ({hiddenname: ' Testcombo ', Fieldlabel: ' Administrative area ', Emptytext: ' Please select ... ', TriggerAction: ' All ', Store:teststore,displayfield: ' Text ', Valuefield: ' Value ', Loadingtext: ' Loading Data ... ', mode: ' Local ', Forceselection:true,typeahead:true,resizable:true,editable:true,anchor: ' 100% ', listeners: {focus: {Fn:functio N (e) {E.expand (); This.doquery (This.allquery, True);},buffer:200},beforequery:function (e) {//Enter pinyin in the text box, Filter by code in store, display only phonetic match options in the drop-down list var combo = e.combo;if (!e.forceall) {var input = E.query;var RegExp = new RegExp ("^" + I Nput + ". *", "I"), Combo.store.filterBy (function (record, id) {var text = record.get (' code '); return regexp.test (text);}); Combo.expand (); Combo.select (0, true);//the cursor defaults to the first item in the drop-down list, so that when the appropriate option is taken, you can select the desired result by using the UP and DOWN ARROW keys and carriage return to false;}}});


Execution effects such as:

ExtJS 3 Implementing the phonetic filtering of the ComboBox drop-down list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.