Flex ArrayCollection - 访问对象方法/属性?

发布于 2024-11-15 18:54:34 字数 2050 浏览 2 评论 0原文

也许我没有得到 ArrayCollection 的真正含义,但首先是一些代码

public var test1:AkwRep = new AkwRep(1,200,200,2,86,2010,2012,334342,"Typ","Standort","Testname","url","owner",true);

// Objekte in ein Array
public var akwArray:Array = new Array(15);

public function addAkw():void {
    akwArray[0] = test1;
}

public var akwList:ArrayCollection = new ArrayCollection(akwArray);

(akw 意味着 Atomkraftwerk -> 核电站;))

所以我有一个带有 akwRep-Objects 的数组。对于数据绑定,我将其放入 ArrayCollection 中。 到目前为止没有问题。但现在我想做一些类似的事情

<s:Label text={akwList.getItemAt(0).getAkwName()} />

,而 getAkwName 是 AkwRep.as 中的一个方法,它返回一个字符串。但这不起作用 - 我无法通过 ArrayCollection 访问任何方法或属性。

有解决办法吗?如果我尝试使用数组,flexbuilder 说他无法使用 akwArray[0] 进行数据绑定...

编辑:一些新代码

这位于我的 main 中的 标记中应用程序

[Bindable]
// AKW-Objekte erstellen
public var test1:AkwRep = new AkwRep(1,200,200,2,86,2010,2012,334342,"Typ","Standort","Testname","url","owner",true);

[Bindable]
// Objekte in ein Array
public var akwArray:Array = new Array(15);

public function addAkw():void {
    akwArray[0] = test1;
}

[Bindable]
public var akwList:ArrayCollection = new ArrayCollection(akwArray);

public function init():void{
    trace(akwList.getItemAt(0));
}

,这是我的 AkwRep.as

public class AkwRep
{
    // Attribute
    // some more attributes right here

    public var typ:String;
    public var standort:String;
    private var akwName:String;

    [Bindable]
    public function get AkwName():String {
        return this.akwName;
    }

    // Konstruktoren
    public function AkwRep(id:Number, x:Number, y:Number, alter:Number, amNetz:Number, offOhneVerl:Number, offMitVerl:Number, leistung:Number, typ:String, standort:String, akwName:String, wikiurl:String, owner:String, moratorium:Boolean) [...]

Maybe i didn't get the real meaning of the ArrayCollection, but first of all some code

public var test1:AkwRep = new AkwRep(1,200,200,2,86,2010,2012,334342,"Typ","Standort","Testname","url","owner",true);

// Objekte in ein Array
public var akwArray:Array = new Array(15);

public function addAkw():void {
    akwArray[0] = test1;
}

public var akwList:ArrayCollection = new ArrayCollection(akwArray);

(akw means Atomkraftwerk -> nuclear power plant ;) )

so i've got an array with akwRep-Objects. For databinding i put it into a ArrayCollection.
No problems so far. But now i want to do something like

<s:Label text={akwList.getItemAt(0).getAkwName()} />

while getAkwName is a method in AkwRep.as which returns a string. but this didn't work - I can not acces any methods or attributes via ArrayCollection.

Is there a solution? If i try it with the array, flexbuilder says he can't do databinding with akwArray[0] ...

Edit: some new code

This is in the <fx:script> tag in my main app

[Bindable]
// AKW-Objekte erstellen
public var test1:AkwRep = new AkwRep(1,200,200,2,86,2010,2012,334342,"Typ","Standort","Testname","url","owner",true);

[Bindable]
// Objekte in ein Array
public var akwArray:Array = new Array(15);

public function addAkw():void {
    akwArray[0] = test1;
}

[Bindable]
public var akwList:ArrayCollection = new ArrayCollection(akwArray);

public function init():void{
    trace(akwList.getItemAt(0));
}

and this is my AkwRep.as

public class AkwRep
{
    // Attribute
    // some more attributes right here

    public var typ:String;
    public var standort:String;
    private var akwName:String;

    [Bindable]
    public function get AkwName():String {
        return this.akwName;
    }

    // Konstruktoren
    public function AkwRep(id:Number, x:Number, y:Number, alter:Number, amNetz:Number, offOhneVerl:Number, offMitVerl:Number, leistung:Number, typ:String, standort:String, akwName:String, wikiurl:String, owner:String, moratorium:Boolean) [...]

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

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

发布评论

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

评论(1

债姬 2024-11-22 18:54:34
<?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"
               creationComplete="init()" xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable]
            public var akwList:ArrayCollection = new ArrayCollection();
            public var test1:AkwRep = new AkwRep(1,"Testname");

            public function addAkw():void {
                akwList.addItem(test1);
            }

        ]]>
    </fx:Script>

    <mx:VBox>
        <s:Label text="{AkwRep(akwList.getItemAt(0)).akwName}" />
        <s:Button click="addAkw();" label="Add" />
    </mx:VBox>
</s:Application>

在 MXML 中

package {

    [Bindable]
    public class AkwRep {

        private var _akwName:String;

        public function get akwName():String {
            return "Name: " + _akwName;
        }

        public function AkwRep(id:Number, akwName:String) {
            _akwName = akwName;
        }
    }
}

在 AkwRep.as 中

<?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"
               creationComplete="init()" xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable]
            public var akwList:ArrayCollection = new ArrayCollection();
            public var test1:AkwRep = new AkwRep(1,"Testname");

            public function addAkw():void {
                akwList.addItem(test1);
            }

        ]]>
    </fx:Script>

    <mx:VBox>
        <s:Label text="{AkwRep(akwList.getItemAt(0)).akwName}" />
        <s:Button click="addAkw();" label="Add" />
    </mx:VBox>
</s:Application>

In MXML

package {

    [Bindable]
    public class AkwRep {

        private var _akwName:String;

        public function get akwName():String {
            return "Name: " + _akwName;
        }

        public function AkwRep(id:Number, akwName:String) {
            _akwName = akwName;
        }
    }
}

In AkwRep.as

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