ItemRenderer Flex 值未根据 ArrayCollection Provider 进行渲染
我在使用 itemRenderer 功能时遇到问题。当使用 ArrayCollection 时,使用 itemRenderer 的 DataGrid 中的可见数据将被渲染得很好。但如果我开始滚动,条目将在使用渲染器的单元格中重复。单元格未根据 id 填充日期。我在这里犯了什么错误。
我读了很多解释,例如:
http://blogs.adobe.com/ aharui/2007/03/thinking_about_item_renderers_1.html
这里是设置数据函数的代码(itemRenderer 正在扩展 HBox):
override public function set data(value:Object):void {
_data = value;
if(data!=null)
{
var maxValue:Number = 0;
var maxFontHeight:int = 18;
for each(var term:ArrayCollection in _data.story)
{
if((term.getItemAt(1) as Number)>maxValue)
maxValue=term.getItemAt(1) as Number;
}
for each(var term:ArrayCollection in _data.story)
{
var FontHeight:int = Math.floor((term.getItemAt(1) as Number) * maxFontHeight / maxValue);
var l:Label = new Label();
l.text = term.getItemAt(0) as String;
l.setStyle("fontWeight","normal");
l.setStyle("fontFamily","Verdana");
l.setStyle("paddingRight",0);
l.setStyle("paddingLeft",0);
l.setStyle("fontSize", FontHeight);
l.setStyle("color", 0x000000);
this.addChild(l);
}
}
}
i have a problem using the itemRenderer functionality. When using an ArrayCollection the visible Data in the DataGrid using the itemRenderer will be rendered just fine. But if i start scrolling the entries are repeating in the cells using the renderer. The cells are not filled with date according to the id. What mistake i'm doing here.
I read a lot of the explainations like:
http://blogs.adobe.com/aharui/2007/03/thinking_about_item_renderers_1.html
here is the code for the set data function (itemRenderer is extending HBox):
override public function set data(value:Object):void {
_data = value;
if(data!=null)
{
var maxValue:Number = 0;
var maxFontHeight:int = 18;
for each(var term:ArrayCollection in _data.story)
{
if((term.getItemAt(1) as Number)>maxValue)
maxValue=term.getItemAt(1) as Number;
}
for each(var term:ArrayCollection in _data.story)
{
var FontHeight:int = Math.floor((term.getItemAt(1) as Number) * maxFontHeight / maxValue);
var l:Label = new Label();
l.text = term.getItemAt(0) as String;
l.setStyle("fontWeight","normal");
l.setStyle("fontFamily","Verdana");
l.setStyle("paddingRight",0);
l.setStyle("paddingLeft",0);
l.setStyle("fontSize", FontHeight);
l.setStyle("color", 0x000000);
this.addChild(l);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在添加新内容之前,您并没有清除渲染器中已有的内容。
尝试将标签的构造移至 createChildren,在集合数据中设置文本(而不是构造另一个标签),并记住在数据为空时清除文本。
您还可以进行一些优化,例如在执行工作之前检查新数据与当前数据是否相同。
You aren't clearing down what's already there in the renderer before adding new stuff.
Try moving the construction of the label to createChildren, setting the text in set data (rather than constructing another label), and remembering to clear the text if the data is null.
There's a few more optimizations you could make such as checking the new data isn't the same as the current data before doing the work, for example.