我发布了自定义itemRenderer see this post的两个问题。我的主要问题是,它总是选择一个错误的行(一个在我选择的行之下)。我现在意识到,当我将itemRenderer的内容保存到dataProvider时会发生这种情况。如果我将此部分编码,dataGrid按预期工作......
这对你有意义吗?
感谢 马库斯
答案 0 :(得分:0)
我将问题提取到某些代码行:
CustomRenderer.mxml:
<mx:Script>
<![CDATA[
import components.ChoiceRenderer;
import mx.rpc.events.ResultEvent;
import mx.events.DataGridEvent;
private function resultHandler(event:ResultEvent):void {
var doc:XML = event.result as XML;
testGrid.dataProvider = doc.Records.BackSide;
}
private function saveBackDataGridContent(event:DataGridEvent):void{
testGrid.dataProvider[event.rowIndex].TextElement = event.currentTarget.itemEditorInstance.text;
}
]]>
</mx:Script>
<mx:HTTPService id="dataService" result="resultHandler(event)" url = "data/example.xml" resultFormat="e4x"/>
<mx:DataGrid id="testGrid" editable="true" itemEditEnd="saveBackDataGridContent(event)">
<mx:columns>
<mx:DataGridColumn itemRenderer="components.ChoiceRenderer" width="230"/>
</mx:columns>
</mx:DataGrid>
ChoiceRenderer.as
package components
{
import mx.containers.HBox;
import mx.controls.CheckBox;
import mx.controls.Label;
public class ChoiceRenderer extends HBox
{
private var correctAnswer:CheckBox;
private var choiceLabel:Label;
public function ChoiceRenderer()
{
super();
setStyle("horizontalScrollPolicy", "off");
correctAnswer = new CheckBox;
addChild(correctAnswer);
choiceLabel = new Label;
addChild(choiceLabel);
}
override public function set data(xmldata:Object):void{
if(xmldata.name() == "BackSide"){
super.data = xmldata.TextElement[0];
choiceLabel.text = xmldata.TextElement[0].toString();
}
}
}
}
的example.xml
<TopContainer>
<Records>
<BackSide>
<TextElement>first</TextElement>
</BackSide>
<BackSide>
<TextElement>second</TextElement>
</BackSide>
<BackSide>
<TextElement>third</TextElement>
</BackSide>
<BackSide>
<TextElement>fourth</TextElement>
</BackSide>
<BackSide>
<TextElement>fifth</TextElement>
</BackSide>
<BackSide>
<TextElement>sixth</TextElement>
</BackSide>
</Records>
由于 马库斯
答案 1 :(得分:0)
这可能不是问题,但我建议在createChildren方法中添加子项,如下所示:
override protected function createChildren() : void {
correctAnswer = new CheckBox();
addChild(correctAnswer);
choiceLabel = new Label();
addChild(choiceLabel);
}