Flex:特殊外壳列表或菜单中的项目? [英] Flex: Special-casing an item in a list or menu?
问题描述
我发现将下拉菜单中的第一项(即 Menu 的一个实例)设为特殊情况通常很有用.例如,如果我想从网络服务提供的列表中选择一种颜色:
I've found it's often useful to special case the first item in a drop-down menu (ie, an instance of Menu). For example, if I want to pick a color from the list provided by a web service:
<mx:PopUpMenuButton id="colorSelelector"
dataProvider="{colorsService.lastResult}" />
我可能还需要一个特殊情况,即输入新颜色",允许用户输入不在列表中的新颜色的 RGB 值.例如:
I might also want a special-case, which is "enter a new color", allowing the user to enter the RGB values for a new color which isn't in the list. For example:
var newColor = { label: "Enter a new color", rgb: null };
然后用于:
<mx:PopUpMenuButton id="colorSelelector"
dataProvider="{colorsService.lastResult}"
lastOption="{newColor}" />
那么,除了更改我从服务中返回的列表之外,还有什么更好的方法可以做到这一点?
So, apart from changing the list I get back from the service, is there any better way to do this?
(而且只是先发制人的评论:这是一种简化……我实际上并不是在尝试制作颜色选择列表)
(and just a preemptive comment: this is a simplification… I'm not actually trying to make a color-picking-list)
推荐答案
所以,除了改变我得到的列表从服务回来,有没有更好的方法来做到这一点?
So, apart from changing the list I get back from the service, is there any better way to do this?
这种方法将是最干净的,无需扩展 HTTPService,它会运行良好(但实际上只是改变了您的结果;)):
This approach is going to be the cleanest, without extending HTTPService, which would work well (but is really just altering your result ;) ):
package
{
import mx.rpc.http.HTTPService;
public class MyHTTPService extends HTTPService
{
public var appendToResult:Object;
public function MyHTTPService(rootURL:String=null, destination:String=null)
{
super(rootURL, destination);
}
[Bindable("resultForBinding")]
override public function get lastResult():Object
{
//I know what my type is, Array as an example
var myResult:Array = operation.lastResult;
myResult.push( this.appendToResult )
return myResult;
}
}
}
这篇关于Flex:特殊外壳列表或菜单中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!