可以用tag的方式來自動完成輸入.
因為來源檔可以是xml,
所以只要能夠從後端資料庫產生xml檔,
應該就能餵給autoComplete了~~
但是....下面的寫法並不支援中文.....
不知是否得以改進~
此外效能如何也尚未得知~
p.s 我辦麥當勞早餐卡了~~
code來自下面這個網址的最後一個例子
http://developer.yahoo.com/flash/astra-flex/autocompletemanager/
- xml version="1.0" encoding="utf-8"?>
- <mx:Application
- xmlns:mx="http://www.adobe.com/2006/mxml"
- xmlns:yahoo="http://www.yahoo.com/astra/2006/mxml">
- layout="absolute"
- <mx:Script>
-
- private function airportFilterFunction(element:*, text:String):Boolean
- {
- var regExp:RegExp = new RegExp(text,autoCompleteMgr.caseSensitive?"":"i");
-
- var b:Boolean = regExp.test(element.city.toString()) ||
- regExp.test(element.name.toString()) ||
- regExp.test(element.code.toString());
-
- return b;
- }
-
- mx:Script>
- <yahoo:AutoCompleteManager
- id="autoCompleteMgr"
- target="{textInput1}"
- dataProvider="{airports.airport}"
- labelField="name"
- filterFunction="{airportFilterFunction}"
- minCharsForCompletion="3" />
-
- <mx:XML id="airports">
- <airports>
-
- <airport>
- <city>Chicagocity>
- <name>Chicago O'Hare Internationalname>
- <code>ORDcode>
- <country>USAcountry>
- airport>
-
- <airport>
- <city>San Franciscocity>
- <name>San Francisco Internationalname>
- <code>SFOcode>
- <country>USAcountry>
- airport>
-
- ...
-
- airports>
- mx:XML>
-
- <mx:Label x="74" y="50" text="Try an airport or airport code:" fontWeight="bold"/>
- <mx:Label x="74" y="67" text="example: "ORD", "Chicago", or "O'Hare"" fontWeight="normal" fontStyle="italic"/>
- <mx:TextInput id="textInput1" left="74" top="93" width="247"/>
-
- mx:Application>
1 則留言:
那看來以後周末的早餐又要麻煩你了 XDD
張貼留言