如何在as3中使用parsley框架注入字典?

发布于 2024-12-02 03:19:48 字数 276 浏览 6 评论 0原文

在我的欧芹容器中,我正在实例化一个包含字典 (flash.utils.Dictionary) 的对象“A”。

我想使用欧芹创建这个字典并将其注入“A”。 该字典对结构为:key=对象 'B' 的 id,value='B' 其中对象“B”也是使用欧芹定义和创建的对象 (所以基本上对结构是对象 id 作为键,对象本身作为值)。

现在,我可以毫无问题地创建“A”和“B”,但似乎无法找到使用欧芹创建此字典的正确方法,也无法将其注入“A”。

非常感谢任何帮助!

提前致谢, 约格夫

In my parsley container, I'm instantiating an object 'A' that contains a Dictionary (flash.utils.Dictionary).

I would like to create this Dictionary using parsley and inject it to 'A'.
This dictionary pairs structure is: key=id of object 'B', value='B'
where object 'B' is also an object which is defined and created using parsley
(so basically the pairs structure is and object id as a key and the object itself as the value).

Now, I have no problem creating 'A' and 'B', but can't seem to find the right way to create this dictionary using parsley, nor injecting it to 'A'.

Any help is highly appreciated!

Thanks in advance,
Yogev

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

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

发布评论

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

评论(1

百善笑为先 2024-12-09 03:19:48

您可以在 context.mxml 中执行此操作:

<mx:Object xmlns:mx="http://www.adobe.com/2006/mxml" 
           xmlns="http://www.spicefactory.org/parsley">

    <mx:Script>
            <![CDATA[
                import com.example.ObjectToInjectX; 
                import com.example.ObjectToInjectY;
                import com.example.MyExampleObject;

            ]]>
    </mx:Script>

    <!-- The class to inject the map into, just declare -->
    <Object type="{MyExampleObject}" id="myExampleObject" />

    <!-- Objects to inject into the Dictionary -->
    <Object type="{ObjectToInjectX}" id="objectToInjectX" />
    <Object type="{ObjectToInjectY}" id="objectToInjectY" />

    <!-- The Dictionary -->
    <Object type="{Dictionary} id="myDictionaryToInject" />
        <DynamicProperty name="itemX" idRef="objectToInjectX" />
        <DynamicProperty name="itemY" idRef="objectToInjectY" />
    </Object>

</mx:Object> 

然后只需在要注入的类中执行以下操作:

public class MyExampleObject
{
     private var _myDictionaryToInject:Dictionary;

     [Inject(id="myDictionaryToInject")]
     public function set myDictionaryToInject( myDictionaryToInject:Dictionary ):void
     {
            _myDictionaryToInject = myDictionaryToInject;
     }
}

You can do this in the context.mxml:

<mx:Object xmlns:mx="http://www.adobe.com/2006/mxml" 
           xmlns="http://www.spicefactory.org/parsley">

    <mx:Script>
            <![CDATA[
                import com.example.ObjectToInjectX; 
                import com.example.ObjectToInjectY;
                import com.example.MyExampleObject;

            ]]>
    </mx:Script>

    <!-- The class to inject the map into, just declare -->
    <Object type="{MyExampleObject}" id="myExampleObject" />

    <!-- Objects to inject into the Dictionary -->
    <Object type="{ObjectToInjectX}" id="objectToInjectX" />
    <Object type="{ObjectToInjectY}" id="objectToInjectY" />

    <!-- The Dictionary -->
    <Object type="{Dictionary} id="myDictionaryToInject" />
        <DynamicProperty name="itemX" idRef="objectToInjectX" />
        <DynamicProperty name="itemY" idRef="objectToInjectY" />
    </Object>

</mx:Object> 

Then simply in the class you want to inject to do the following:

public class MyExampleObject
{
     private var _myDictionaryToInject:Dictionary;

     [Inject(id="myDictionaryToInject")]
     public function set myDictionaryToInject( myDictionaryToInject:Dictionary ):void
     {
            _myDictionaryToInject = myDictionaryToInject;
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文