问题描述
我有一个自定义组件,其中有一个advancedDataGrid。我想要这个组件是可重用的,因此需要将数据标签selectionMode设置为组件属性。在mxml中,我想要这样设置属性:
< 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.0encoding =utf-8?>
< s:组xmlns:fx =http://ns.adobe.com/mxml/2009
xmlns:s =库://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mxwidth =638height =500>
< fx:声明>
<! - 将非视觉元素(例如服务,价值对象)放在这里 - >
< / fx:声明>
< fx:脚本>
<![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:脚本>
< mx:AdvancedDataGrid id =adgItemsdesignViewDataType =flatwidth =100%height =100%>
< mx:columns>
< mx:AdvancedDataGridColumn headerText =列1dataField =col1/>
< mx:AdvancedDataGridColumn headerText =列2dataField =col2/>
< mx:AdvancedDataGridColumn headerText =Column 3dataField =col3/>
< / mx:columns>
< / mx:AdvancedDataGrid>
< / s:组>
<! - Application.mxml - >
<?xml version =1.0encoding =utf-8?>
< s:应用程序xmlns:fx =http://ns.adobe.com/mxml/2009
xmlns:s =库://ns.adobe.com/flex/spark
xmlns:mx =library://ns.adobe.com/flex/mxminWidth =955minHeight =600xmlns:comp =*>
< fx:声明>
<! - 将非视觉元素(例如服务,价值对象)放在这里 - >
< / fx:声明>
< comp:MyComponent x =272y =86itemsSelectionMode =singleCell/>
< / s:应用程序>
错误:值无效:multipleRows。它必须是oneRow,multipleRows,singleCell,multipleCells之一。
您的自定义组件中有公共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;
}
I have a custom component of which have a advancedDataGrid inside it. I want this component to be reusable so need is set the datagid selectionMode as a component property.
In mxml i want set property like this:
<comp:MyComp itemDataGridSelectionMode="singleCell" .../>
Inside MyComp actionScript i have a metatag like this:
[Inspectable(enumeration="singleRow, multipleRows, singleCell, multipleCells", defaultValue="singleRow")]
public var itemDataGridSelectionMode:String;
How do i bind this itemDataGridSelectionMode variable to advancedDatagrid selectionMode?
UPDATE: Here is a small test application fully working code:
<!--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>
Error: Invalid value: multipleRows. It must be one of singleRow, multipleRows, singleCell, multipleCells.
Where you have your public var within your custom component, do this:
[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;
}
这篇关于自定义组件dataGrid selectionMode作为属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!