Datagrid 和内联项渲染器问题
我有一个带有两个内联项目渲染器的数据网格。我的 DG 的数据提供者是一个嵌套对象(对象内的对象内的对象,即 3 层)。
Main Object - 1st Level
|
2nd Level Object 1
|
3rd level object '1' => ('name'=>somename,'id'=>someid)
3rd level object '2'
.
.
.
.
3rd level object 'n'
2nd Level Object 2
|
3rd level object '1' => ('name'=>somename,'id'=>someid)
3rd level object '2'
.
.
.
.
3rd level object 'n'
我使用 2 个项目渲染器(每个数据网格列一个),分别循环到第二级对象 1 和 2(第二级对象是动态对象数组,其中对象的数量不断变化)。
在项目渲染器中,我使用 foreach 循环遍历第二级对象,然后显示数据。数据是一个链接按钮,单击该按钮时,会调用远程对象函数以从数据库中删除数据,
现在在远程对象函数调用的结果事件上,我调用该函数来重新填充 DG,以便显示更新的数据。
当我单击第一行中的链接按钮时,后端工作得很好(数据从数据库中删除,刷新的数据发回),但由于某种原因,删除的数据突然出现在第二行中。
当我从第二行删除它时,它出现在第三行(后端没有任何反应,因为数据已被删除)..依此类推,直到它出现在最后一行,然后 DG 看起来完全一样应该在第一次删除后进行处理。
这只是开始。第二个项目渲染器还显示一个链接按钮,单击该按钮时,会在上一列中显示该数据(可以删除该数据的列)。当我单击第一行时,数据会添加到第二行的前一列中......依此类推......
基本上,我的 DG 表现得非常奇怪。我重写了项目渲染器中的设置数据函数来刷新数据并调用其 invalidateDisplayList。我还在每次刷新后调用 Datagrid 的 invalidateDisplayList 函数。行为保持不变。
请帮助我...
这是我的数据库代码:
<mx:DataGrid id="privilegesDG" width="100%" variableRowHeight="true" minHeight="500">
<mx:columns>
<mx:DataGridColumn headerText="Roles Assigned">
<mx:itemRenderer>
<fx:Component>
<mx:VBox creationComplete="box1_creationCompleteHandler()">
<fx:Script>
<![CDATA[
import com.pm.modules.events.UpdateDBEvent;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.Label;
import mx.controls.LinkButton;
import mx.events.FlexEvent;
override public function set data(value:Object):void{
super.data = value;
super.invalidateDisplayList();
}
protected function box1_creationCompleteHandler():void
{
for each(var temp:Object in data.roles){
var hgrp:HBox = new HBox();
hgrp.autoLayout = false;
var lbl:Label = new Label();
lbl.text = temp.rname;
var lb:LinkButton = new LinkButton();
lb.label = 'X';
lb.id = temp.rid.toString();
lb.focusEnabled = true;
lb.addEventListener(MouseEvent.CLICK,handleClick);
hgrp.addElement(lbl);
hgrp.addElement(lb);
this.addElement(hgrp);
}
}
protected function handleClick(event:MouseEvent):void{
dispatchEvent(new UpdateDBEvent(UpdateDBEvent.ON_DELETE_PRIVILEGE_ROLE_MAP,0,0,0,event.target.id,0,true));
}
]]>
</fx:Script>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Roles Not Assigned">
<mx:itemRenderer>
<fx:Component>
<mx:VBox creationComplete="box1_creationCompleteHandler()">
<fx:Script>
<![CDATA[
import com.pm.modules.events.UpdateDBEvent;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.Label;
import mx.controls.LinkButton;
import mx.events.FlexEvent;
override public function set data(value:Object):void{
super.data = value;
super.invalidateDisplayList();
}
protected function box1_creationCompleteHandler():void
{
for each(var temp:Object in data.notroles){
var lb:LinkButton = new LinkButton();
lb.label = temp.rname;
lb.id = temp.rid.toString();
lb.addEventListener(MouseEvent.CLICK,handleClick);
this.addElement(lb);
}
}
protected function handleClick(event:MouseEvent):void{
dispatchEvent(new UpdateDBEvent(UpdateDBEvent.ON_ASSIGN_ROLE_TO_PRIVILEGE,data.ID,event.target.id,0,0,0,true));
}
]]>
</fx:Script>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
updateDBEvent 负责调用更新数据库的远程函数。
I have a datgrid with two inline item renderers. The dataprovider for my DG is a nested object (objects within objects within objects i.e 3-layered).
Main Object - 1st Level
|
2nd Level Object 1
|
3rd level object '1' => ('name'=>somename,'id'=>someid)
3rd level object '2'
.
.
.
.
3rd level object 'n'
2nd Level Object 2
|
3rd level object '1' => ('name'=>somename,'id'=>someid)
3rd level object '2'
.
.
.
.
3rd level object 'n'
I use 2 item renderers (one for each datagrid column) which loops thro the 2nd level object1 and 2 respectively (the 2nd level object is a dynamic array of objects, in that the number of objects within keep changing).
Within the item renderer I loop thro the 2nd level object using a foreach and then display the data. The data is a linkbutton, which when clicked , calls a remote object function to delete the data from the database
now on the result event of the remote object function call, i call the function to repopulate the DG, so that the updated data is displayed.
When i click on the linkbutton in the first row, the backend works perfectly fine (the data gets deleted from the database and the refreshed data is sent back), but for some reason, the deleted data suddenly appears in the 2nd row.
When i delete it from the second row, it appears on the 3rd row (nothing happens in the backend since the data is already deleted).. and so on, till it appears on the last row and then the DG looks exactly the way it shld have looked after the first delete.
This is just the beginning. The second item renderer also displays a linkbutton, which when clicked, displays that data in the previous column (the one where this data can be deleted). When i click on 1st row, the data gets added in the previous column of the second row .. and so on..
Basically, my DG is acting really weird. I overrided the set data function in the item renderer to refrsh the data and called its invalidateDisplayList. I also call the Datagrid's invalidateDisplayList function after each refresh. The behavior remains the same.
Please help me on this ...
Here's my DB code :
<mx:DataGrid id="privilegesDG" width="100%" variableRowHeight="true" minHeight="500">
<mx:columns>
<mx:DataGridColumn headerText="Roles Assigned">
<mx:itemRenderer>
<fx:Component>
<mx:VBox creationComplete="box1_creationCompleteHandler()">
<fx:Script>
<![CDATA[
import com.pm.modules.events.UpdateDBEvent;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.Label;
import mx.controls.LinkButton;
import mx.events.FlexEvent;
override public function set data(value:Object):void{
super.data = value;
super.invalidateDisplayList();
}
protected function box1_creationCompleteHandler():void
{
for each(var temp:Object in data.roles){
var hgrp:HBox = new HBox();
hgrp.autoLayout = false;
var lbl:Label = new Label();
lbl.text = temp.rname;
var lb:LinkButton = new LinkButton();
lb.label = 'X';
lb.id = temp.rid.toString();
lb.focusEnabled = true;
lb.addEventListener(MouseEvent.CLICK,handleClick);
hgrp.addElement(lbl);
hgrp.addElement(lb);
this.addElement(hgrp);
}
}
protected function handleClick(event:MouseEvent):void{
dispatchEvent(new UpdateDBEvent(UpdateDBEvent.ON_DELETE_PRIVILEGE_ROLE_MAP,0,0,0,event.target.id,0,true));
}
]]>
</fx:Script>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Roles Not Assigned">
<mx:itemRenderer>
<fx:Component>
<mx:VBox creationComplete="box1_creationCompleteHandler()">
<fx:Script>
<![CDATA[
import com.pm.modules.events.UpdateDBEvent;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.Label;
import mx.controls.LinkButton;
import mx.events.FlexEvent;
override public function set data(value:Object):void{
super.data = value;
super.invalidateDisplayList();
}
protected function box1_creationCompleteHandler():void
{
for each(var temp:Object in data.notroles){
var lb:LinkButton = new LinkButton();
lb.label = temp.rname;
lb.id = temp.rid.toString();
lb.addEventListener(MouseEvent.CLICK,handleClick);
this.addElement(lb);
}
}
protected function handleClick(event:MouseEvent):void{
dispatchEvent(new UpdateDBEvent(UpdateDBEvent.ON_ASSIGN_ROLE_TO_PRIVILEGE,data.ID,event.target.id,0,0,0,true));
}
]]>
</fx:Script>
</mx:VBox>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
The updateDBEvent is responsible for calling the remote function that updates the DB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不太确定这是否有帮助,需要查看您的代码才能确定。但如果您希望 DataGrid 重绘,请不要调用
,而是调用
Not really sure if this will help, would need to look at your code to be able to say for sure. But if you want the DataGrid to redraw, dont call the
instead, call