You need to sign in to do that
Don't have an account?
Vetriselvan Manoharan
Binding values in tree view
Hi, Guys.
I need to bind values in tree view based on field in the same object. For eg: I have article object which has a field called special notes. Now the special notes should be the parent in the tree and article should be child. I tried something.
public List<Article__c> articles {get; set;}
public Map<String, Article__c> articlesMap {get; set;}
public Hydra_MarshTreeViewController (){
articles = [ SELECT Id, Name, SpecialisedNotes__c from Article__c ];
System.debug('Hi' + articles);
articlesMap = new Map<String, Article__C>();
for(Article__c article : articles)
{
articlesMap.put(article.SpecialisedNotes__c, article);
}
System.debug('ArticleMap' +articlesMap);
}
Here is My VF page:
<apex:repeat value="{!articlesMap}" var="arc">
<li class="closed"><span class="folder">{!arc}</span>
<ul>
<apex:repeat value="{!articlesMap[arc]}" var="c">
<li><span class="file"><a href="Article?id={!articlesMap[arc]}" target="_blank">{!articlesMap[arc]}</a></span></li>
</apex:repeat>
</ul>
</li>
</apex:repeat>
Please help me
I need to bind values in tree view based on field in the same object. For eg: I have article object which has a field called special notes. Now the special notes should be the parent in the tree and article should be child. I tried something.
public List<Article__c> articles {get; set;}
public Map<String, Article__c> articlesMap {get; set;}
public Hydra_MarshTreeViewController (){
articles = [ SELECT Id, Name, SpecialisedNotes__c from Article__c ];
System.debug('Hi' + articles);
articlesMap = new Map<String, Article__C>();
for(Article__c article : articles)
{
articlesMap.put(article.SpecialisedNotes__c, article);
}
System.debug('ArticleMap' +articlesMap);
}
Here is My VF page:
<apex:repeat value="{!articlesMap}" var="arc">
<li class="closed"><span class="folder">{!arc}</span>
<ul>
<apex:repeat value="{!articlesMap[arc]}" var="c">
<li><span class="file"><a href="Article?id={!articlesMap[arc]}" target="_blank">{!articlesMap[arc]}</a></span></li>
</apex:repeat>
</ul>
</li>
</apex:repeat>
Please help me
Use this Controller method and vf page.
Controller,
public List<Article__c> articles {get; set;}
public Map<String, list<Article__c>> articlesMap {get; set;}
public Hydra_MarshTreeViewController (){
articles = [ SELECT Id, Name, SpecialisedNotes__c from Article__c ];
System.debug('Hi' + articles);
articlesMap = new Map<String, list<Article__C>>();
for(Article__c article : articles)
{
if(!articlesMap.containsKey(article.SpecialisedNotes__c))
articlesMap.put(article.SpecialisedNotes__c, new list<Article__c>());
articlesMap.get(article.SpecialisedNotes__c).add(article);
}
System.debug('ArticleMap' +articlesMap);
}
VF Page
<ul>
<apex:repeat value="{!articlesMap}" var="arc">
<li class="closed"><span class="folder">{!arc}</span>
<ul>
<Apex:repeat value="{!articlesMap[arc]}" var="article">
<li><span class="file"><a href="Article?id={article.Id}" target="_blank">{!article.Name}</a></span></li>
</apex:repeat>
</ul>
</li>
</apex:repeat>
</ul>
Thanks
Nitin
All Answers
Please try this vf page code
<ul>
<apex:repeat value="{!articlesMap}" var="arc">
<li class="closed"><span class="folder">{!arc}</span>
<ul>
<li><span class="file"><a href="Article?id={!articlesMap[arc]}" target="_blank">{!articlesMap[arc]}</a></span></li>
</ul>
</li>
</apex:repeat>
</ul>
Thanks
Nitin
Nope it doesn't work. The child may have more than one article. So it should display all the article based on Special notes(Parent) field in article. Also I need the article name in the child. But now it is displaying only Id.
Thanks,
Vetri
Use this Controller method and vf page.
Controller,
public List<Article__c> articles {get; set;}
public Map<String, list<Article__c>> articlesMap {get; set;}
public Hydra_MarshTreeViewController (){
articles = [ SELECT Id, Name, SpecialisedNotes__c from Article__c ];
System.debug('Hi' + articles);
articlesMap = new Map<String, list<Article__C>>();
for(Article__c article : articles)
{
if(!articlesMap.containsKey(article.SpecialisedNotes__c))
articlesMap.put(article.SpecialisedNotes__c, new list<Article__c>());
articlesMap.get(article.SpecialisedNotes__c).add(article);
}
System.debug('ArticleMap' +articlesMap);
}
VF Page
<ul>
<apex:repeat value="{!articlesMap}" var="arc">
<li class="closed"><span class="folder">{!arc}</span>
<ul>
<Apex:repeat value="{!articlesMap[arc]}" var="article">
<li><span class="file"><a href="Article?id={article.Id}" target="_blank">{!article.Name}</a></span></li>
</apex:repeat>
</ul>
</li>
</apex:repeat>
</ul>
Thanks
Nitin
Thanks. But still the child is not looping it.. Any ideas?
Vetri
And what it is printing right now?
Thanks
Nitin
This is how I done it nitin. Added an else part worked.
else
{
articlesMap.get(article.SpecialisedNotes__c).add(article);
}
Thanks,
Vetri