Recursive chain

1 view
Skip to first unread message

Vincent Pérès

unread,
Oct 1, 2008, 4:27:54 AM10/1/08
to chainjs
Hello,

Great library! I would like to add a recursive part.

My JSON results are like that :

{
"id":"0711719721123",
"description_text":[
"ATV Offroad Fury 2 provides expansive off-road racing gameplay
packed with more courses, modes, tricks, and ATVs, plus online
gameplay via the network adapter to heighten the racing experience.
Players will choose from more than 20 licensed and team-sponsored ATVs
from top-tier manufacturers and off-road sponsors. Every featured ATV
will be true to spec, allowing for realistic handling and reactions in
every situation."],
"genre_facet":["Online","Bike","Video Games"]
}

My template is here :

<div id="results">
<div id="item">
<b class="id"></b><br />
<p class="description"></p>
<ul id="facets">
<li class="facet"></li>
</ul>
<br />
</div>
</div>

And my javascript :

$.getJSON("results.html", function (json) {
$('#results').items(json.response.docs).chain({
'.description': '{description_text}',
'#facets': function(){

}
});
});

Well, the basic stuffs are working (loop on results and display id/
description), but I'm lost for the second part : how to display my
facets?
I tried some possibilities to chain #facets, but I didn't find the
current value... so if you have any idea?

Thank you !
Vincent

Vincent Pérès

unread,
Oct 1, 2008, 8:40:36 AM10/1/08
to chainjs
Hello again :)

I hope I'm on the right way, I had a looked at this code :
http://friendpaste.com/5fZDAn7m
And now my code :

$.getJSON("results.html", function (json){
$('#results').items(json.response.docs).chain({
'.description': '{description_text}',
builder: function(root){
if(this.item().genre_facet){
//$
('.facets').chain('clone').appendTo().items(this.item().genre_facet).chain();
$
('.facets').chain('clone').appendTo(this.find('.facets_loop')).items([{"facet":"facet
1"},{"facet":"facet 2"}]).chain();
}
}
});
});

And template :
<div id="results">
<div class="item">
<b class="id"></b><br />
<p class="description"></p>
<div class="facets">
<ul class="facets_loop">
<li class="facet"></li>
</ul>
</div>
<br />
<br />
</div>
</div>

It is almost working with the uncommented line, facets are display but
the loop is on the whole "ul li"... I would like to loop only on "li".
The, I tried to use the commented line, but it is not working (I
changed the template according to the data) :
"genre_facet":["Online","Bike","Video Games"] is not "genre_facet":
["facet":"Online","facet":"Bike","facet":"Video Games"]
How to display this kind of data?
"genre_facet":["Online","Bike","Video Games"] is equal to
"genre_facet":[0:"Online",1:"Bike",2:"Video Games"]


Thank you very much!
Vincent

Rizqi Ahmad

unread,
Oct 1, 2008, 11:10:08 AM10/1/08
to chainjs
hi Vincent,

try this please: http://friendpaste.com/kxqdH8Nc

you have to change:
<li class="facet"></li> to <li><span class="facet"/></li>

and change the javascript as shown in the code.

regards,
Rizqi

Vincent Pérès

unread,
Oct 1, 2008, 11:26:15 AM10/1/08
to chainjs
Hello,

Thank you, it is working with facets like that : [{"facet":"facet1"},
{"facet":"facet2"}]
But my JSON is like that : ["Online","Bike","Video Games"] (equal to
[0:"Online",1:"Bike",2:"Video Games"])
I changed <li><span class="facet"/></li> to <li><span class="0"/></
li>, but only the first letters for every facets are displayed.
Is there any var like '*' or I have to modify the builder to do that?

Thank you very much,
Vincent

Rizqi Ahmad

unread,
Oct 1, 2008, 1:10:32 PM10/1/08
to chainjs
Hi,

try to use in builder:
chain({'.facet': '{$data}'})

regards
Rizqi
Reply all
Reply to author
Forward
0 new messages