1

ArrayCollection「アイテム」と呼びます。これは基本的に、階層データのフラットなコレクションです(各アイテムにはプロパティがParentありChildrenます)。データを階層形式で表示したいAdvancedDataGridので、基本的にこれを実行するだけで、正常に表示されます。

// Note: RootItems would be an ArrayCollection that is updated so only the
// top level items are within (item.Parent == null).
var hd:HierarchicalData = new HierarchicalData(model.RootItems);
var hcv:HierarchicalCollectionView = new HierarchicalCollectionView(hd);

myDataGrid.dataProvider = hdc;

これは機能しますが、コレクションが更新されmyDataGridたときに更新を確認できるようにしたいです(子の更新を取得しないため、最上位のタスクのみを取得します)。これを行う簡単な方法はありますか?拡張して変更時にアラートを出すクラスを作成する必要があると思いますが、それはかなり遅いように思えます。あなたが提供できるどんな助けにも前もって感謝します!ItemsRootItemsHierarchicalDataItems

4

1 に答える 1

2

この問題を解決するには、2 つのオプションがあります。独自の実装を作成するかIHierarchicalData(拡張する必要はなくHierarchicalData、この特定のケースでは再利用できるコードはあまりありません)、標準に適合するようにデータの処理方法を少し変更します使用事例:

[Bindable] // make it bindable so that the HierarchicalCollectionView gets notified when the object changes
class Foo // your data class
{
    // this constructor is needed to easily create the rootItems below
    public function Foo(children:ArrayCollection = null)
    {
        this.children = children;
    }

    // use an ArrayCollection which dispatches an event if one of its children changes
    public var children:ArrayCollection;

    // all your other fields
}

// Create your rootItems like this. Each object can contain a collection of children
// where each of those can contain children of its own and so forth...
var rootItems:ArrayCollection = new ArrayCollection([
    new Foo(
        new ArrayCollection([
            new Foo(),
            new Foo(),
            new Foo(
                new ArrayCollection([
                    // ...
                ]),
            new Foo()
        ])
    ),
    new Foo(
        // ...
    ),
    // ...
]);

// Create the HierarchicalData and HierachicalCollectionView
var hd:IHierarchicalData = new HierarchicalData(rootItems);

[Bindable]
var hcv:IHierarchicalCollectionView = new HierarchicalCollectionView(hd);

次に、ADG でhcvasdataProviderを使用し、そのメソッドを使用してアイテムを追加および削除できます。アイテムを追加、削除、または更新するたびに、ADG が更新されます。

それが本当に不可能でない限り、標準的な方法で行うことをお勧めします。

于 2011-04-04T18:08:00.443 に答える