简体   繁体   English

Flex中的ItemRenderer与Repeater

[英]ItemRenderer vs Repeater in Flex

Any one of you know about the difference between ItemRenderer and Repeater. 你们谁都知道ItemRenderer和Repeater之间的区别。 Both are behaving the same almost. 两者的行为几乎相同。 Any difference is there? 有什么区别吗?

Any one of you know about the difference between ItemRenderer and Repeater. 你们谁都知道ItemRenderer和Repeater之间的区别。 Both are behaving the same almost. 两者的行为几乎相同。 Any difference is there? 有什么区别吗?

I'm not sure how they could be behaving the same, but without seeing your code, it is hard to judge. 我不确定它们如何表现相同,但是如果看不到您的代码,就很难判断。 I will try to explain the difference; 我将尝试解释差异。 or rather; 更确切地说; what each one is. 每个是什么。

Under the hood An itemRenderer is a ClassFactory . 在后台,itemRenderer是ClassFactory A factory is a design pattern for a class that creates other classes. 工厂是用于创建其他类的类的设计模式。 In the context of Flex, itemRenderers are used in list based classes, such as a DataGrid or List. 在Flex的上下文中,itemRenderers用于基于列表的类,例如DataGrid或List。 The list based classes accept a dataProvider and only render the elements seen on the screen. 基于列表的类接受一个dataProvider,并且仅呈现在屏幕上看到的元素。 As you scroll through the list, each component generated by the itemRenderer is reused. 在列表中滚动时,itemRenderer生成的每个组件都会被重用。 I call this renderer recycling. 我将此渲染器称为回收。 So, it is important that you implement your itemRenderer to respond to the dataChange event so it is always properly rendering the data it is supposed to represent. 因此,重要的是要实现itemRenderer以响应dataChange事件,以便它始终正确呈现应该表示的数据。 More info on itemRenderer components . 有关itemRenderer组件的更多信息。

A Repeater is like a loop in MXML. 中继器就像MXML中的循环。 Using a repeater does not provide any of the "renderer" benefits that a list based class does. 使用转发器不会提供基于列表的类提供的任何“渲染器”好处。 Everything created inside your loop is renderered at once. 循环中创建的所有内容都将立即渲染。

So, let's say you have a dataProvider with 100 images. 因此,假设您有一个包含100张图片的dataProvider。 You have space to show 10 of them on screen. 您有空间在屏幕上显示其中的10个。 With a list based class, flex will render and load 10 images; 对于基于列表的类,flex将渲染并加载10张图像; changing what is loaded as you scroll through the list. 滚动列表时更改加载的内容。 With a Repeater Flex will render and load all 100 at once even though not all of them are on the screen. 使用Repeater Flex可以一次渲染并加载所有100个,即使不是所有这些都在屏幕上。

The biggest difference: Repeater has been deprecated discontinued. 最大的区别是:Repeater已被 弃用,已 停产。 It exists as an mx component in Flex 3 only and there is no Spark equivalent in Flex 4. It is encouraged that you use DataGroup+ItemRenderer instead. 仅在Flex 3中作为mx组件存在,而在Flex 4中没有等效的Spark。建议您改用DataGroup + ItemRenderer。 The main reason for this is very clearly explained in @www.Flextras.com's answer. 在@ www.Flextras.com的答案中非常清楚地解释了这样做的主要原因。

Besides that, IMO for anything but the most basic usage Repeater can be a serious pain. 除此之外,除了最基本的用途之外,IMO对于中继器来说可能是一个严重的痛苦。 Its paradigm is completely different from all the other Flex components , whereas a DataGroup+ItemRenderer approach is very much in line with the Flex component set. 它的范例与所有其他Flex组件完全不同 ,而DataGroup + ItemRenderer方法与Flex组件集非常一致。

Bottom line: do not use Repeater . 底线: 请勿使用Repeater There's nothing you can do with Repeater that you can't do with DataGroup+ItemRenderer. 与Repeater相比,您无能为力,而对DataGroup + ItemRenderer则无能为力。 (Unless perhaps you're stuck with Flex 3 for some reason. See Amy's comments for more on this.) (除非您出于某种原因而无法使用Flex3。有关更多信息,请参阅Amy的评论。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM