本文介绍了软硬度:特殊套管中的项目列表或菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这是非常有用的特殊情况下,在下拉菜单(菜单即实例)的第一个项目。举例来说,如果我想选择由Web服务提供的列表中选择颜色:

 < MX:PopUpMenuButton等ID =colorSelelector
    的dataProvider ={colorsService.lastResult}/>
 

我也可能需要一个特殊情况,这是进入一个新的颜色,允许用户输入的RGB值的新彩色这不是在该列表中。例如:

  VAR newColor = {标签:进入一个新的色彩,RGB:空};
 

然后用

 < MX:PopUpMenuButton等ID =colorSelelector
    的dataProvider ={colorsService.lastResult}
    lastOption ={newColor}/>
 

那么,除了改变列表中我得到的服务回报,有没有更好的方式来做到这一点?

(和仅preemptive评论:这是一个简化的......我没有真正试图使一个颜色采摘列表)

解决方案

此方法将是最干净的,不延长的HTTPService,这将很好地工作(但实际上只是改变你的结果;)):

 包
{
    进口mx.rpc.http.HTTPService;

    公共类MyHTTPService扩展的HTTPService
    {
    公共变种appendToResult:对象;

    公共职能MyHTTPService(则rootURL:字符串=空,目标:字符串= NULL)
    {
    超(则rootURL,目的地);
    }

        [可绑定(resultForBinding)]
        重写公共职能得到的lastResult():对象
        {
        //我知道我的类型,数组作为一个例子
        VAR myResult中:数组= operation.lastResult;
        myResult.push(this.appendToResult)
            返回myResult中;
        }
    }
}
 

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}" />

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 };

Then used with:

<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)

解决方案

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;
        }
    }
}

这篇关于软硬度:特殊套管中的项目列表或菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:23