在网格数据提供程序中使用自定义类对象时如何重写设置数据方法

发布于 2024-10-27 03:29:52 字数 4012 浏览 0 评论 0原文

* 新手警报 *

我有一个包含 5 列的 AdvancedDataGrid。带有标题标签的第二列需要能够在每个单元格中包含多行。

最初,我的网格的 dataprovider 定义如下:

[Bindable]
public var mappedTagsArray:ArrayCollection = new ArrayCollection( [ 
    { name: "garbage-garbage", semanticTags: "garbage-flirt\ngarbage-garbage\ngarbage-noise\ngarbage-profanity", exitStrategy: "Fallback", confirmationMode: "IF NECESSARY", confirmationPromptlet: "cp5" }, 
    { name: "report-sim", semanticTags: "enquire-sim\nreport-sim", exitStrategy: "Direct", confirmationMode: "NEVER", confirmationPromptlet: "cp6" }
] );

Columns 标签定义如下,使用内联 TextArea 组件来处理一个单元格中的多行:

<mx:AdvancedDataGridColumn id="semanticTags" headerText="Labels" dataField="semanticTags" editable="false">
    <mx:itemRenderer>
        <fx:Component>
            <mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off"
                                             top="0" bottom="0" right="0" left="0">
                <fx:Script>
                    <![CDATA[
                        import com.nuance.csportal.mw_api.CallerIntent;
                        public function get value() : String
                        {
                            return ta_labels.text;
                        }
                        override public function set data(value:Object):void
                        {
                            super.data = value;
                            ta_labels.text = value.semanticTags;
                        }
                    ]]>
                </fx:Script>
                <!-- BUG: Scroll bar is fixed in one location; does not move with resizing of cell -->
                <s:TextArea id="ta_labels" heightInLines="2" editable="false" borderVisible="false"
                                                    horizontalScrollPolicy="auto" verticalScrollPolicy="auto" contentBackgroundAlpha="0"
                                                    top="0" bottom="0" right="0" left="0"/>
            </mx:HBox>                                      
        </fx:Component>
    </mx:itemRenderer>
</mx:AdvancedDataGridColumn>

在这种情况下,semanticTags 多行显示在 Labels 列的单元格中。


现在我创建了一个名为 CallerIntent 的自定义 ActionScript 类:

package com.nuance.csportal.mw_api
{
    import mx.controls.List;

    public class CallerIntent
    {
        public function CallerIntent( id:int, name:String, semanticTags:Array, exitStrategy:String, confirmationMode:String, confirmationPromptlet:String )
        {
            this.id = id;
            this.name = name;
            this.semanticTags = semanticTags;
            this.exitStrategy = exitStrategy;
            this.confirmationMode = confirmationMode;
            this.confirmationPromptlet = confirmationPromptlet;
        }

        public var id:int;
        public var name:String;
        public var semanticTags:Array;
        public var exitStrategy:String;
        public var confirmationMode:String;
        public var confirmationPromptlet:String;
    }
}

在我的表单创建完成时调用的 init() 方法中,我填充网格的数据提供程序:

public function init( event:Event ):void
{
    var st1:Array = new Array( "garbage-flirt", "garbage-garbage", "garbage-noise", "garbage-profanity" );
    var st2:Array = new Array( "enquire-sim", "report-sim" );
    var ci1:CallerIntent = new CallerIntent( 1, "garbage-garbage", st1, "Fallback", "IF NECESSARY", "cp1" );
    var ci2:CallerIntent = new CallerIntent( 2, "report-sim", st2, "Direct", "NEVER", "cp2" );

    mappedTagsArray.addItem( ci1 );
    mappedTagsArray.addItem( ci2 );
}

在这种情况下,我的应用程序在覆盖设置数据方法中崩溃 ta_labels.text = value.semanticTags; 和 无法访问空对象引用的属性或方法。

这是真的——当我使用 CallerIntent 对象的 ArrayCollection 而不是未命名对象的 ArrayCollection 时,值保持为 null(在这种情况下,值将保存未命名的对象)。

我尝试将函数的签名更改为 覆盖公共函数集数据(值:CallerIntent):void 并得到了不兼容的覆盖。

有什么想法吗?谢谢! 邦妮

* Newbie Alert *

I have an AdvancedDataGrid with 5 columns. The second column, with header Labels, needs to be able to contain multiple lines in each cell.

Initially, my grid's dataprovider was defined as follows:

[Bindable]
public var mappedTagsArray:ArrayCollection = new ArrayCollection( [ 
    { name: "garbage-garbage", semanticTags: "garbage-flirt\ngarbage-garbage\ngarbage-noise\ngarbage-profanity", exitStrategy: "Fallback", confirmationMode: "IF NECESSARY", confirmationPromptlet: "cp5" }, 
    { name: "report-sim", semanticTags: "enquire-sim\nreport-sim", exitStrategy: "Direct", confirmationMode: "NEVER", confirmationPromptlet: "cp6" }
] );

The Columns label was defined as follows, with an inlined TextArea component to handle the multiple lines in one cell:

<mx:AdvancedDataGridColumn id="semanticTags" headerText="Labels" dataField="semanticTags" editable="false">
    <mx:itemRenderer>
        <fx:Component>
            <mx:HBox horizontalScrollPolicy="off" verticalScrollPolicy="off"
                                             top="0" bottom="0" right="0" left="0">
                <fx:Script>
                    <![CDATA[
                        import com.nuance.csportal.mw_api.CallerIntent;
                        public function get value() : String
                        {
                            return ta_labels.text;
                        }
                        override public function set data(value:Object):void
                        {
                            super.data = value;
                            ta_labels.text = value.semanticTags;
                        }
                    ]]>
                </fx:Script>
                <!-- BUG: Scroll bar is fixed in one location; does not move with resizing of cell -->
                <s:TextArea id="ta_labels" heightInLines="2" editable="false" borderVisible="false"
                                                    horizontalScrollPolicy="auto" verticalScrollPolicy="auto" contentBackgroundAlpha="0"
                                                    top="0" bottom="0" right="0" left="0"/>
            </mx:HBox>                                      
        </fx:Component>
    </mx:itemRenderer>
</mx:AdvancedDataGridColumn>

In this scenario, the semanticTags multiple lines are displayed in the Labels column's cell.


Now I've created a custom ActionScript class called CallerIntent:

package com.nuance.csportal.mw_api
{
    import mx.controls.List;

    public class CallerIntent
    {
        public function CallerIntent( id:int, name:String, semanticTags:Array, exitStrategy:String, confirmationMode:String, confirmationPromptlet:String )
        {
            this.id = id;
            this.name = name;
            this.semanticTags = semanticTags;
            this.exitStrategy = exitStrategy;
            this.confirmationMode = confirmationMode;
            this.confirmationPromptlet = confirmationPromptlet;
        }

        public var id:int;
        public var name:String;
        public var semanticTags:Array;
        public var exitStrategy:String;
        public var confirmationMode:String;
        public var confirmationPromptlet:String;
    }
}

And in my init() method which is called upon creationComplete of my form, I populate my grid's dataprovider:

public function init( event:Event ):void
{
    var st1:Array = new Array( "garbage-flirt", "garbage-garbage", "garbage-noise", "garbage-profanity" );
    var st2:Array = new Array( "enquire-sim", "report-sim" );
    var ci1:CallerIntent = new CallerIntent( 1, "garbage-garbage", st1, "Fallback", "IF NECESSARY", "cp1" );
    var ci2:CallerIntent = new CallerIntent( 2, "report-sim", st2, "Direct", "NEVER", "cp2" );

    mappedTagsArray.addItem( ci1 );
    mappedTagsArray.addItem( ci2 );
}

In this scenario, my app crashes in the override set data method at
ta_labels.text = value.semanticTags;
with
Cannot access a property or method of a null object reference.

This is true – value remains null when I’m using an ArrayCollection of CallerIntent objects as opposed to the ArrayCollection of unnamed objects (in this case, value will hold the unnamed Object).

I tried changing the function’s signature to
override public function set data(value:CallerIntent):void
and got Incompatible Override.

Any ideas? Thanks!
Bonnie

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

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

发布评论

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

评论(1

若沐 2024-11-03 03:29:52

我已经解决了我的问题。
在首次调用重写的设置数据方法后,我的网格的数据提供程序正在填充。
因此我只需要放置

 if ( value != null )

这段代码。

I've fixed my problem.
My grid's dataprovider is getting populated AFTER the overridden set data method is first called.
Hence I just had to put

 if ( value != null )

around this code.

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