簡體   English   中英

在網格的數據提供程序中使用自定義類對象時,如何覆蓋設置數據方法

[英]How to override set data method when using custom class objects in grid's dataprovider

*新手警報*

我有5列的AdvancedDataGrid。 第二列的標題為Labels,必須能夠在每個單元格中包含多行。

最初,我的網格的數據提供程序定義如下:

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

在這種情況下,“語義標簽”多行顯示在“標簽”列的單元格中。


現在,我創建了一個名為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;
    }
}

在表單的creationComplete上調用的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時,值保持為空(在這種情況下,值將保存未命名的對象)。

我嘗試更改函數的簽名以覆蓋公共函數集data(value:CallerIntent):void並獲得了Incompatible Override。

有任何想法嗎? 謝謝! 邦妮

我已經解決了我的問題。 在首先調用覆蓋的set數據方法之后,將填充網格的dataprovider。 因此,我只需要放

 if ( value != null )

圍繞此代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM