2

変数があり、actionscript と flex を使用してこの変数を arraycollection または array に入れたい

以下はコードです

var xyz:int=30;

var myArray:Array = [ {Month: "January", Views_Week1:xyz}, { Month: "June",        

    Views_Week2: 13 }, { Month:" December", Views_Week3: 14} ];

pageViews= new ArrayCollection(myArray);

また

pageViews= new ArrayCollection(myArray);
[
    { Month: January, Views_Week1: xyz},
    { Month:June, Views_Week2: 13},
    { Month: december, Views_Week3: 14}])

お願いします

4

2 に答える 2

1

That does not work that way. When defining a variable, it is basically just present in that scope. You could declare it [Bindable] in the scope of a class, so the class would propagate changes with a PropertyChangeEvent of type PropertyChangeEvent.PROPERTY_CHANGE. This would allow you using BindingUtils, ChangeWatcher and MXML databinding with <{} /> declarative bindings.

You need to define a class, declare the class or a field [Bindable] and then create instances of the class and reference these through the ArrayCollection. Using vanilla object won't get you somewhere, since those can't dispatch Events.

    package
    {
      [Bindable]
      public class Person
      {
        public var name:String;

        public function Person(n:String)
        {
          name = n;
        }
      }
    }

    const source:Array = [new Person('Fred')]
        , collection:IList = new ArrayCollection(source);

Data binding relies on some key mechanisms like event dispatching, that is something to keep in mind. Also, in one way or the other, a reference to the data being changed need to in the different scopes, where the notification of the change is needed.

于 2012-05-23T08:41:23.020 に答える
1
pageViews= new ArrayCollection(myArray);

良さそう。ArrayCollectionただし、2番目のものは、を初期化してからオブジェクトを再度割り当てようとしている場所では意味がありません(;ステートメント終了マーカーがあるため、これは発生しません)。

それはあなたにとってうまくいきませんか?

于 2012-05-23T08:09:28.137 に答える