开发者

Data in Components Spark in a ItemRenderer in Flex

开发者 https://www.devze.com 2023-02-28 10:30 出处:网络
I need to create a slideshow using data received from another view. I\'m calling the slideshow\'s view like this:

I need to create a slideshow using data received from another view.

I'm calling the slideshow's view like this:

<s:List id = "list" dataProvider = "{actions}"
change = "navigator.pushView (DetailsProduct, list.selectedItem) ">
<s:itemRenderer>
<fx:Component>
<s:MobileIconItemRenderer
labelField = "title"
messageField = "description"
decoratorClass = "{data.icon}">
</s:MobileIconItemRenderer>
</fx:Component>
</s:itemRenderer>
</s:List>

I think the problem is the time to send the parameter because I'm passing the selected item and must pass the entire list.

And the other problem is in the view, I can see the object received outside the list but not inside it.

With this code the object appears, but the back and forward buttons doesn't work.

<s:List id = "myList"
     dataProvider = "{actions}">
</s:List>

<s:Image source="{data.icon}"/>
<s:Label text="{data.title}"/>
<s:L开发者_如何学Pythonabel text="{data.description}"/>

<s:HGroup>
<s:Button label="Forward" click="imgForward(event)"/>
<s:Button label="Back" click="imgBack(event)"/>
</s:hgroup>

And this code shows nothing, even the object being called the same way.

<s:List id = "myList"
     dataProvider = "{actions}">
         <s:itemRenderer>
     <fx:Component>
     <s:ItemRenderer>
         <s:Image source="{data.icon}"/>
         <s:Label text="{data.title}"/>
         <s:Label text="{data.description}"/>
     </s:ItemRenderer>
     </fx:Component>
     </s:itemRenderer>
</s:List>

<s:HGroup>
     <s:Button label="Forward" click="imgForward(event)"/>
     <s:Button label="Back" click="imgBack(event)"/>
</s:hgroup>


I actually don't understand what you're trying to accomplish. The data property is defined in the IDataRenderer interface.

When a component is used as a renderer, the data element that the instance of component represents is passed into the renderer using the data property.

You didn't quantify what "works or "not works" mean, so I'm not sure what your desired behavior is, nor why one is wrong, and one isn't. In your first sample, I would not expect a data property to have any value:

<s:List id="myList"
    creationComplete="criaLista(event)"
    dataProvider="{actions}">
</s:List>

<s:Image source="{data.icon}"/>
<s:Label text="{data.title}"/>
<s:Label text="{data.description}"/>

I'm not sure what the dataProvider contains, but if it contains objects, I would expect something to be displayed in the list. I would expect the Image, and the labels to display no visual elements, because the data property is most likely null. If you wanted to reference the item selected in the list, instead of accessing data, you could access something like this:

<s:Image source="{myList.selectedItem.icon}"/>
<s:Label text="{myList.selectedItem.title}"/>
<s:Label text="{myList.selectedItem.description}"/>

It uses the selectedItem property from the list instance to modify the display elements.

In your second sample, where you do create an itemRenderer, I would expect it to work:

<s:List id="myList"
    creationComplete="criaLista(event)"
    dataProvider="{actions}">
        <s:itemRenderer>
    <fx:Component>
    <s:ItemRenderer>
        <s:Image source="{data.icon}"/>
        <s:Label text="{data.title}"/>
        <s:Label text="{data.description}"/>
    </s:ItemRenderer>
    </fx:Component>
    </s:itemRenderer>
</s:List>

However, the itemRenderer does nothing to position the image or two labels, so I would expect them to be layered on top of each other, which is probably not desirable behavior. You can set the X and Y values to size them.

If you want to elaborate on the specific problems; why your first sample 'works' and the second doesn't, please do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号