Apache flex 灵活项目渲染器-don';如果为空,是否包含元素?
我有如下项目渲染器代码:Apache flex 灵活项目渲染器-don';如果为空,是否包含元素?,apache-flex,formatting,mxml,itemrenderer,Apache Flex,Formatting,Mxml,Itemrenderer,我有如下项目渲染器代码: <s:HGroup> <s:Label text="{data.DateTime}"/> <s:VGroup> <s:Label text="{data.Description}"/> <s:Label text="{data.Amount}"/> </s:VGroup> </s:HGroup> 说明是可选字段。。我希望如果
<s:HGroup>
<s:Label text="{data.DateTime}"/>
<s:VGroup>
<s:Label text="{data.Description}"/>
<s:Label text="{data.Amount}"/>
</s:VGroup>
</s:HGroup>
说明是可选字段。。我希望如果描述字段为null,则金额字段将向上移动,但现在只有一个空格。有没有办法在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"
creationComplete="application1_creationCompleteHandler(event)"
>
<fx:Script>
<![CDATA[
import mx.charts.DateTimeAxis;
import mx.events.FlexEvent;
[Bindable]
private var data:Object;
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
var newData:Object = new Object();
newData.DateTime = new Date();
newData.Description = "Description";
newData.Amount = 12345;
data = newData;
}
protected function setNull_clickHandler(event:MouseEvent):void
{
var newData:Object = new Object();
newData.DateTime = new Date();
newData.Description = null;
newData.Amount = 12345;
data = newData;
}
protected function setValue_clickHandler(event:MouseEvent):void
{
var newData:Object = new Object();
newData.DateTime = new Date();
newData.Description = "Description";
newData.Amount = 12345;
data = newData;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup>
<s:HGroup>
<s:Button id="setNull" label="Set Null" click="setNull_clickHandler(event)"/>
<s:Button id="setValue" label="Set Description" click="setValue_clickHandler(event)"/>
</s:HGroup>
<s:Label text="Renderer"/>
<s:HGroup>
<s:Label text="{data.DateTime}"/>
<s:VGroup>
<s:Label text="{data.Description}"
visible="{data.Description != null}"
includeInLayout="{data.Description != null}"
/>
<s:Label text="{data.Amount}" />
</s:VGroup>
</s:HGroup>
</s:VGroup>
</s:Application>