[ExtJS4] multi-choice pull-down ticket (with checkbox)

Source: Internet
Author: User
Preface Extjs is easy to create a multi-choice drop-down list. You can use ExtformComboBox to set multiSelect to true. But how can I add a checkbox before each drop-down? ComboBox itself does not have such configuration. There is a preface: Ext js is easy to create a multi-choice drop-down list. Use Ext. form. ComboBox and set multiSelect to true. But how can I add a checkbox before each drop-down? ComboBox itself does not have such a configuration, and there is an extension like "Ext. ux. form. MultiSelect". If it works, all the options are displayed. You can't expand only one such component on your own. You can use the listConfig configuration of ComboBox to display the interface. You can configure itemTpl of listConfig to display the Display Effect of each option. [html] itemTpl: Ext. create ('ext. xtemplate ',' {Value} '). The function interaction display effect is not described. When an option is selected, the checkbox in front of it should be selected; otherwise, the previous checkbox should be unselected. The solution is to configure listeners [html] listeners: {itemclick: function (view, record, item, index, e, eOpts) {var isSelected = view in listConfig. isSelected (item); var checkboxs = item. getElementsByTagName ("input"); if (checkboxs! = Null) {var checkbox = checkboxs [0]; if (! IsSelected) {checkbox. checked = true;} else {checkbox. checked = false ;}}} the above dynamic store mode is available in the local store state. [Html] var states2 = Ext. create ('ext. data. store', {fields: ['abbr ', 'name'], data: [{"abbr": "AL", "name": "Alabama "}, {"abbr": "AK", "name": "Alaska" },{ "abbr": "AZ", "name ": "Arizona"} //...]}); however, a problem may occur when using ajax to retrieve store data. [Html] proxy: {type: 'ajax ', url:'/users. json ', reader: {type: 'json', root: 'users'}. If you click the drop-down list next time, the selected check box will be deselected. The reason is that this method will update the combobox drop-down option (combobox), and try to add processing in the refresh and render events, and it will not work. The final tracing code can be implemented by overwriting onItemSelect. Complete code [html] Ext. define ('ext. ux. multiComboBox ', {extend: 'ext. form. combobox', alias: 'widget. multicombobox ', xtype: 'multicombobox', initComponent: function () {this. multiSelect = true; this. listConfig = {itemTpl: Ext. create ('ext. xtemplate ',' {Value} '), onItemSelect: function (record) {var node = this. getNode (record); if (node) {Ext. fly (node ). addCls (this. selectedItemCls); var checkboxs = node. getElementsByTagName ("input"); if (checkboxs! = Null) {var checkbox = checkboxs [0]; checkbox. checked = true ;}}, listeners: {itemclick: function (view, record, item, index, e, eOpts) {var isSelected = view. isSelected (item); var checkboxs = item. getElementsByTagName ("input"); if (checkboxs! = Null) {var checkbox = checkboxs [0]; if (! IsSelected) {checkbox. checked = true;} else {checkbox. checked = false ;}}} this. callParent ();}});
Related Article

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.