One implementation of extjs multi-level linkage menu

Source: Internet
Author: User
1. the combos control in extjs can be used to define the data source store in the following way: Code

VaR Store =   New Ext. Data. simplestore ({ // Define the data source displayed in the combo box
// Fields: ['item', 'itemvalue'],
Fields :[ ' Item ' , ' Itemvalue ' , ' Parentid ' , ' Strvalueid ' ],
Data: arrayitemstore
});

Fields can set multiple fields, as long as they are consistent with the value assignment of the data attribute. The value assignment of data must be a nested array. The word element of the array is the array defined by fields, as shown below:

Data:
[

[ ' Company 1 ' , ' 2458 ' , ' 0 ' , ' 48 ' ], // It must be consistent with the array dimension defined by fields.
[ ' Company 2 ' , ' 542 ' , ' 0 ' , ' 478 ' ],
[ ' Company 3 ' , ' 45 ' , ' 0 ' , ' 47 ' ]

]

 

 

2. Join the company and region and associate them with parentid. You can add the followingCode:

Code

VaR CO = Ext. getcmp ( " CO " );
VaR DQ = Ext. getcmp ( " DQ " );
If ( ! Ext. isempty (CO )){
CO. On ( ' Beforeselect ' , Function (Box, record, index ){
DQ. Store. Filter ( ' Parentid ' , Record. Get ( ' Strvalueid ' ));
}

 

The record here is the data set of the currently selected item passed by extjs, so that we can conveniently obtain the data item we used to define the store for combos.
The DQ. Store. filter method is used to filter data in the combos region. It is important to note that the region combos must contain all the regions.
To read data from the database in the combos region, use the following format:

Code

// Function that gets City store
Function Getcitystore ()
{
VaR Store =   New Ext. Data. jsonstore ({
URL: ' Get-city-by-country-ID ' ,
// Baseparams: countryID: countryidvar,
Fields :[
{Name: ' Cityid ' , Type: ' Int ' },
' Cityname '  
]
});
Return Store;
}

// Than I have a countries combo
VaR Countries =   New Ext. Form. ComboBox ({
ID: ' Country ' ,
Store: getcountrystore (),
Typeahead: True ,
Triggeraction: ' All ' ,
Emptytext: ' ... ' ,
Listeners :{
Select :{
FN: Function (Combo, value ){
VaR Modeldest = Ext. getcmp ( ' City ' );
// Set and disable cities
Modeldest. setdisabled ( True );
Modeldest. setvalue ( '' );
Modeldest. Store. removeall ();
// Reload region store and enable Region
Modeldest. Store. Reload ({
Params: {countryID: combo. getvalue ()}
});
Modelreg. setdisabled ( False );
}
}
}
})

 

 

Method 3:

VaR Provinces = [[1, 'Beijing' ], [2, 'Shanghai' ];
  1. VaRCities =NewArray ();
  2. Cities [1] = [11,'Haidian'], [22,'Dongcheng'];
  3. Cities [2] = [[33,'Whampoa'], [44,'Pudong'], [55,'Jingand'];
  4. VaRComboprovinces =NewExt. Form. ComboBox ({
  5. Store:NewExt. Data. simplestore ({
  6. Fields :["Provinceid","Provincename"],
  7. Data: Provinces
  8. }),
  9. Listeners :{
  10. Select:Function(Combo, record, index ){
  11. Combocities. clearvalue ();
  12. Combocities. Store. loaddata (cities [record. Data. provinceid]);
  13. }
  14. },
  15. Valuefield:"Provinceid",
  16. Displayfield:"Provincename",
  17. Mode:'Local',
  18. Forceselection:True,
  19. Blanktext:'Select a province',
  20. Emptytext:'Select a province',
  21. Hiddenname:'Provinceid',
  22. Editable:False,
  23. Triggeraction:'All',
  24. Allowblank:True,
  25. Fieldlabel:'Select a province',
  26. Name:'Provinceid',
  27. Width: 80
  28. });
  29.  VaRCombocities =NewExt. Form. ComboBox ({
  30. Store:NewExt. Data. simplestore ({
  31. Fields :["Cityid",'Cityname'],
  32. Data: []
  33. }),
  34. Valuefield:"Cityid",
  35. Displayfield:"Cityname",
  36. Mode:'Local',
  37. Forceselection:True,
  38. Blanktext:'Select region',
  39. Emptytext:'Select region',
  40. Hiddenname:'Cityid',
  41. Editable:False,
  42. Triggeraction:'All',
  43. Allowblank:True,
  44. Fieldlabel:'Select region',
  45. Name:'Cityid',
  46. Width: 80
  47. });

 

VaR provinces = [[1, 'beijing'], [2, 'shanghai']; var cities = new array (); Cities [1] = [11, 'haidian '], [22, 'dongcheng']; cities [2] = [[33, 'whampoa '], [44, 'pudong'], [55, 'Security ']; var comboprovinces = new Ext. form. comboBox ({store: New Ext. data. simplestore ({fields: ["provinceid", "provincename"], data: provinces}), listeners: {select: function (combo, record, index) {combocities. clearvalue (); combocities. store. loaddata (cities [record. data. provinceid]) ;}}, valuefield: "provinceid", displayfield: "provincename", mode: 'local', forceselection: True, blanktext: 'select a province ', emptytext: 'select a province ', hiddenname: 'cmdid', Editable: false, triggeraction: 'all', allowblank: True, fieldlabel: 'select a province', name: 'cmdid ', width: 80}); var combocities = new Ext. form. comboBox ({store: New Ext. data. simplestore ({fields: ["cityid", 'cityname'], data: []}), valuefield: "cityid", displayfield: "cityname", mode: 'local ', forceselection: True, blanktext: 'select region', emptytext: 'select region', hiddenname: 'cityid', Editable: false, triggeraction: 'all', allowblank: True, fieldlabel: 'select region', name: 'cityid', width: 80 });

Do not set the ID of the ComboBox control to the same as that of the hiddenname control. Otherwise, the system selects no option and does not know if it is a bug of ComboBox.

 

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.