我有一个自定义组件,里面有一个advancedDataGrid。我希望这个组件可以重用,因此需要将datagid selectionMode设置为组件属性。
在mxml中我想要这样的set属性:
<comp:MyComp itemDataGridSelectionMode="singleCell" .../>
在MyComp actionScript中,我有一个像这样的元标记:
[Inspectable(enumeration="singleRow, multipleRows, singleCell, multipleCells", defaultValue="singleRow")]
public var itemDataGridSelectionMode:String;
如何将此itemDataGridSelectionMode变量绑定到advancedDatagrid selectionMode? p>
更新:这是一个小型测试应用程序完全正常工作的代码:
<!--MyComp.mxml-->
<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="638" height="500">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
[Inspectable(enumeration="singleRow, multipleRows, singleCell, multipleCells", defaultValue="singleRow")]
public function set itemsSelectionMode(value:String):void
{
this.adgItems.selectionMode = value;
}
public function get itemsSelectionMode():String
{
return this.adgItems.selectionMode;
}
]]>
</fx:Script>
<mx:AdvancedDataGrid id="adgItems" designViewDataType="flat" width="100%" height="100%">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="Column 1" dataField="col1"/>
<mx:AdvancedDataGridColumn headerText="Column 2" dataField="col2"/>
<mx:AdvancedDataGridColumn headerText="Column 3" dataField="col3"/>
</mx:columns>
</mx:AdvancedDataGrid>
</s:Group>
<!-- Application.mxml -->
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" xmlns:comp="*">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<comp:MyComponent x="272" y="86" itemsSelectionMode="singleCell"/>
</s:Application>
错误:无效值:multipleRows。它必须是singleRow,multipleRows,singleCell,multipleCells之一。
答案 0 :(得分:2)
如果您的自定义组件中包含public var,请执行以下操作:
[Inspectable(enumeration="singleRow, multipleRows, singleCell, multipleCells", defaultValue="singleRow")]
public function set itemDataGridSelectionMode(value:String):void
{
advancedDatagrid.selectionMode = value;
}
public function get itemDataGridSelectionMode():String
{
return advancedDatagrid.selectionMode;
}
答案 1 :(得分:1)
我猜你可以将itemDataGridSelectionMode设置为[Bindable],然后可以将它与AdvancedDataGrid的selectionMode属性绑定。
答案 2 :(得分:0)
一种方法是:
BindingUtils.bindProperty(datagridId, 'selectionMode', this, itemDataGridSelectionMode);
或使用setter方法而不是变量定义。