سؤال

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

هل كانت مفيدة؟

المحلول

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;
     }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top