Flex 项目渲染器 - 如果为 null,则不包含元素?

发布于 2024-10-31 01:48:53 字数 382 浏览 6 评论 0原文

我有这样的项目渲染器代码:

<s:HGroup>
    <s:Label text="{data.DateTime}"/>

    <s:VGroup>
        <s:Label text="{data.Description}"/>
        <s:Label text="{data.Amount}"/>
    </s:VGroup>
</s:HGroup>

描述是一个可选字段。我希望如果“描述”字段为空,“金额”字段就会向上移动,但现在只有一个空白区域。 mxml 有什么办法可以实现这一点吗?我希望它们位于单独的字段中,因为我计划使“描述”可编辑,但“金额”是固定的。

I have item renderer code like this:

<s:HGroup>
    <s:Label text="{data.DateTime}"/>

    <s:VGroup>
        <s:Label text="{data.Description}"/>
        <s:Label text="{data.Amount}"/>
    </s:VGroup>
</s:HGroup>

Description is an optional field.. I would like if the Description field is null for the Amount field to move up, but right now there is just an empty space. Is there any way to achieve this in mxml? I want them in separate fields because I plan to make the Description editable, but the Amount fixed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌逼全场 2024-11-07 01:48:53

我编写了一个简单的应用程序来模拟项目渲染器的行为。
诀窍是使用 visibleincludeInLayout 属性:

<?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>

I wrote simple application that simulates a behaviour of Item renderer.
The trick is to use visible and includeInLayout properties:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文