[英]Flex Data Binding
I'm trying to databind an object's property to a ComboBox's (editable=true) text property. 我正在尝试将对象的属性数据绑定到ComboBox的(editable = true)文本属性。 This property is of type Number. 此属性的类型为Number。
If I bind using the inline syntax, it works: 如果我使用内联语法进行绑定,则可以使用:
<mx:ComboBox text="{myObj.prop}">
If I bind using mx:Binding, I receive an error: 如果我使用mx:Binding绑定,则会收到错误消息:
<mx:Binding source="{myObj.prop}" destination="combobox.text" />
// 1067: Implicit coercion of a value of type Number to an unrelated type String.
Why this difference in behaviour? 为什么这种行为上的差异?
Property definition: 属性定义:
private var _prop: Number;
[Bindable] public function get prop(): Number { return _prop; }
public function set prop(value: Number): void { _prop = value; }
Initially I thought: The mx:Binding
source should be the field name itself, not the value. 最初,我认为: mx:Binding
源应该是字段名称本身,而不是值。 Flex is complaining because it is dereferencing myObj.prop
because of the {}
and seeing the value there (a Number
) when it wants a string with the field name. Flex抱怨,因为它由于{}
而取消引用myObj.prop
,并在需要带有字段名称的字符串时看到那里的值(一个Number
)。
<mx:Binding source="myObj.prop" destination="combobox.text" />
However: 然而:
ActionScript inside curly braces is allowed in the mx:Binding
source expression, and is required in this case. 大括号内的ActionScript在mx:Binding
源表达式中是允许的,在这种情况下是必需的。 See Adobe's data binding examples . 请参阅Adobe的数据绑定示例 。
The text
property is expecting a String
to be assigned to it, so you will want to cast in your binding: text
属性期望将一个String
分配给它,因此您将需要强制绑定:
<mx:Binding source="{String(myObj.prop)}" destination="combobox.text" />
My apologies for the initial misleading answer, hopefully this is on the right track. 我对最初的误导性答案表示歉意,希望这是对的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.