• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

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
0
royjayd
Asked:
royjayd
  • 4
  • 4
  • 3
2 Solutions
 
zzynxSoftware engineerCommented:
Using Flex's Repeater component is the way to go: http://livedocs.adobe.com/flex/3/html/help.html?content=repeater_3.html
0
 
royjaydAuthor Commented:
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
0
 
Pravin AsarCommented:
For the data collection rendering you can simply user  mx:List



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

0
The IT Degree for Career Advancement

Earn your B.S. in Network Operations and Security and become a network and IT security expert. This WGU degree program curriculum was designed with tech-savvy, self-motivated students in mind – allowing you to use your technical expertise, to address real-world business problems.

 
royjaydAuthor Commented:
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
0
 
zzynxSoftware engineerCommented:
>> 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'
0
 
Pravin AsarCommented:
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

0
 
royjaydAuthor Commented:
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>


0
 
zzynxSoftware engineerCommented:
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
0
 
royjaydAuthor Commented:
>>>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>

0
 
Pravin AsarCommented:
Here is a simple example.  How you can implement your custom item renderer for mx:list conrol


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:ArrayCollection id="qArray">
      <mx:source>
            
      <mx:Object qid="1" description="Question Text 1"/>
      <mx:Object qid="2" description="Question Text 2"/>
      <mx:Object qid="3" description="Question Text 3"/>
      <mx:Object qid="4" description="Question Text 4"/>
      <mx:Object qid="5" description="Question Text 5"/>
      </mx:source>
</mx:ArrayCollection>
<mx:List dataProvider="{qArray}" width="500" height="500" alternatingItemColors="[#ffffff,#dddddd]">
      <mx:itemRenderer>
            <mx:Component>
                  <mx:RichTextEditor showControlBar="false" title="Question {data.qid}:" width="500" height="95" verticalScrollPolicy="off" htmlText="{data.description}"/>
            </mx:Component>
      </mx:itemRenderer>
</mx:List>
</mx:Application>
0
 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now