开发者

Flex: Failing gracefully on ReferenceError: Error #1056:

开发者 https://www.devze.com 2022-12-23 08:19 出处:网络
Hi I have a text field which I would like to bind to a dynamic object. <mx:TextInput id=\"ti4\" text=\"{selectedObj[\'someProp\']}\" valueCommit=\"{selectedObj[\'someProp\'] = ti4.text}\"x=\"1011.

Hi I have a text field which I would like to bind to a dynamic object.

<mx:TextInput id="ti4" text="{selectedObj['someProp']}" valueCommit="{selectedObj['someProp'] = ti4.text}"  x="1011.5" y="835"/>

If the property doesn't exist I get a reference error - 开发者_高级运维Is there any way to fail a little more gracefully?

Any ideas much appreciated.


You could wrap your accessor in a method which uses a try block to catch the reference error and return some reasonable default value.

<mx:TextInput text="{getMyProperty(selectedObject, 'someProp')}" ... />

...

protected function getMyProperty (fromObject:Object, propName:String):* {
    try {
        return fromObject[propName];
    } catch (err:Error) {
        return ""; // default value
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消