This is a simple example. You just need to explain it in a step-by-step manner, from simple to complex!
The example consists of two parts: lcombo.html and lcombo. js.
Lcombo.html
View plain
Copy to clipboard
Print
?
- <! Doctype HTML public
"-// W3C // dtd html 4.01 transitional // en"
- Http://www.w3.org/TR/html4/loose.dtd"
>
- <HTML>
- <Head>
- <Meta http-equiv = "Content-Type"
Content =
"Text/html; charset = UTF-8"
>
- <LINK rel = "stylesheet"
Type =
"Text/CSS"
Href =
"../Extjs-2.0/resources/CSS/ext-all.css"
>
- <SCRIPT type = "text/JavaScript"
Src =
"../Extjs-2.0/adapter/EXT/ext-base.js"
> </SCRIPT>
- <SCRIPT type = "text/JavaScript"
Src =
"../Extjs-2.0/ext-all-debug.js"
> </SCRIPT>
- <SCRIPT type = "text/JavaScript"
Src =
"Lcombo. js"
> </SCRIPT>
- <! -- A localization script file comes here -->
- <SCRIPT type = "text/JavaScript"
>
- Ext. onready (lcombo. App. init, lcombo. app );
- </SCRIPT>
- <Title> linked combos example </title>
- </Head>
- <Body>
- </Body>
- </Html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
This is ext's smallest HTML!
Do not forget to change the ext class library and resource references to deploy your ext!
Lcombo. js
View plain
Copy to clipboard
Print
?
- /**
- * Ext 2.0 linked combos tutorial
- * By Jozef sakalos, aka Saki
- * Extjs.com/learn/tutorial:linked_combos_tutorial_for_ext_2
- */
- // Reference local blank image
- Ext. blank_image_url = '../extjs-2.0/resources/images/default/s.gif'
;
- Ext. namespace ('lcombo'
,
'Lcombo. Countries'
,
'Lcombo. Cities'
);
- Lcombo. Countries = [
- ['Usa'
,
'United States of America'
]
- , ['D'
,
'Germany'
]
- , ['F'
,
'France'
]
- , ['Gb'
,
'Great Britain'
]
- ];
- Lcombo. Cities = [
- [1, 'usa'
,
'New York'
]
- , [2, 'usa'
,
'Cleveland'
]
- , [3, 'usa'
,
'Austin'
]
- , [4, 'usa'
,
'Los Angeles'
]
- , [5, 'D'
,
'Berline'
]
- , [6, 'D'
,
'Bonn'
]
- , [7, 'F'
,
'Paris'
]
- , [8, 'F'
,
'Nice'
]
- , [9, 'gb'
,
'London'
]
- , [10, 'gb'
,
'Glasgow'
]
- , [11, 'gb'
,
'Verpool'
]
- ];
- // Create Application
- Lcombo. APP = Function
(){
- // Do not access DOM from here; elements don't exist yet
- // Private Variables
- // Private Functions
- // Public Space
- Return
{
- // Public methods
- Init: Function
(){
- VaR
Form =
New
Ext. formpanel ({
- Renderto: Document. Body
- , Width: 400
- , Height: 300
- , Style: 'margin: 16px'
- , Bodystyle: 'padding: 10px'
- , Title: 'linked combos'
- , Defaults: {xtype: 'combo'
}
- , Items :[{
- Fieldlabel: 'select country'
- , Displayfield: 'country'
- , Valuefield: 'cid'
- , Store: New
Ext. Data. simplestore ({
- Fields: ['cid'
,
'Country'
]
- , Data: lcombo. Countries
- })
- , Triggeraction: 'all'
- , Mode: 'local'
- , Listeners: {select: {fn: Function
(Combo, value ){
- VaR
Combocity = ext. getcmp (
'Combo-City'
);
- Combocity. setvalue (''
);
- Combocity. Store. Filter ('cid'
, Combo. getvalue ());
- }}
- }
- },{
- Fieldlabel: 'select City'
- , Displayfield: 'city'
- , Valuefield: 'id'
- , ID: 'combo-City'
- , Store: New
Ext. Data. simplestore ({
- Fields: ['id'
,
'Cid'
,
'City'
]
- , Data: lcombo. Cities
- })
- , Triggeraction: 'all'
- , Mode: 'local'
- , Lastquery :''
- }]
- });
- }
- };
- } (); // End of app
- // End of File