Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

populating data in richtext from a For loop

hi guys
I have a question . I am getting the data from the backend as a arraycollection and trying to populate the rich text areas.

here is my flex code

for (var i= 0; i < screenList.length;  i++){
screens = screenList[i] as ScreenDTO;
for(var j=0; j < screens.questionList;  j++){
question = screens.questionList[i] as QuestionDTO;
if(question != null){
Alert.show("question id", questions.id);  -- this is the question id 
Alert.show("question desc", questions.description);  -- this is the question name
	}
} }

Open in new window

I have 25 such questions ids and names which i am trying to populate in the richtext areas

<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin1" width="1050" title="this should contain the 1st question id from the above for loop"   text="this should contain the 1st question  name from the above for loop"   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>

<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin1" width="1050" title="this should contain the 2nd question id "   text="this should contain the 2nd question  name "   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>

....
and so on

any easy way and best way to do it ?

thanks
SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

i dont know if that will help me

<mx:Repeater id="myrep" dataProvider="{myAC}">
    <mx:Label id="Label1" text="This is loop #{myrep.currentItem}"/>
  </mx:Repeater>

 repeater repeats the Label (in my case rich text areas), i cant do that because i already have multiple rich text areas and in between i have non-rich text areas like text boxes.

i need something like

for(var j=0; j < screens.questionList;  j++){
question = screens.questionList[j] as QuestionDTO;
if(question != null){
Alert.show("question id", questions.id);  -- this is the question id
Alert.show("question desc", questions.description);  -- this is the question name
}
}

1st question
<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin1" width="1050" title="question.id"   text="question.description"   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>

2nd Question
<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin2" width="1050" title="question.id"   text="question.description "   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>


thanks
For the data collection rendering you can simply user  mx:List



<mx:List id="myList" dataProvider="{myDP}" width="220" height="200" showDataTips="true"/>

Avatar of Jay Roy

ASKER

ok thanks but i am having difficulty understanding your comment.
where do i use  <mx:List id="myList" dataProvider="{myDP}" width="220" height="200" showDataTips="true"/>   ?

I am already iterating the list (in my case questionList)  usng a for loop like this
for(var j=0; j < screens.questionList;  j++){
question = screens.questionList[j] as QuestionDTO; //QuestionDTO has id,description
if(question != null){
Alert.show("question id", questions.id);  -- this question id should be set in richtext title
Alert.show("question desc", questions.description);  -- this question name should be set in richtext text

}
}

thx
>> i cant do that because i already have multiple rich text areas and in between i have non-rich text areas like text boxes.
I see.

I think using what you find
@ http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_8.html 
and
@ http://livedocs.adobe.com/flex/3/html/help.html?content=containers_intro_6.html
should work.

1. You should look for child components with the names "questoin1", "questoin2", "questoin3",...
    (and this is possible in a loop with inside
     
var nameToLookFor : String = "question" + i;

Open in new window

   )
2. Once found you can set their properties 'title' and 'text'
With any Flex control, you can have custom item renderer.

Look at "Example: Using an item renderer with a List control" at


http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_8.html

Avatar of Jay Roy

ASKER

ok...but what i had in mind is can i just set the first id/description in the list to first rich text box
the second  id/description in the list to second rich text box and so on?


for(var j=0; j < screens.questionList;  j++){
question = screens.questionList[j] as QuestionDTO; //QuestionDTO has id,description
if(question != null){
Alert.show("question id", questions.id);  -- this question id should be set in richtext title
Alert.show("question desc", questions.description);  -- this question name should be set in richtext text

}
}


1st question
<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin1" width="1050" title="screens.questionList[j].id"   --> j=1 text="screens.questionList[j].description"   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>

2nd Question
<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin2" width="1050" title="screens.questionList[j].id"   --> j=2 text="screens.questionList[j].description "   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>


1. Is your previous comment intended to me or to pravinasar? If to me: see my previous comment
2. There's no need to always repost your same code
Avatar of Jay Roy

ASKER

>>>Is your previous comment intended to me or to pravinasar?
both

>>>There's no need to always repost your same code
Pay a little more attention, its not same code, see my code in BOLD

1st question
<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin1" width="1050" title="screens.questionList[j].id"   --> j=1 text="screens.questionList[j].description"   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>

2nd Question
<mx:VBox width="66%" styleName="responseBox">
<mx:HBox width="66%">
<mx:RichTextEditor id="questoin2" width="1050" title="screens.questionList[j].id"   --> j=2 text="screens.questionList[j].description "   maxHeight="261" creationComplete="expcoll(event)"/>
</mx:HBox>                  
</mx:VBox>

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanx 4 axxepting