Hello,
I ran across this little issue, and I just don''t get it.
I have a php script returning this JSON object:
{"items":[{"id":9,"comment":"test
text"},{"id":12,"comment":"another
text"}]}
I am making a request to the script, looping through JSON object,
inserting the new content into my div (hidden) and then use a sliding
effect on each item to reveal the new content.
Here is the issue, if I just do an Insertion.Top it insert all items
fine, but if I do use an Effect.SlideDown it stops after the first
item at the Effect.
I think it might be because the Effect can''t seem to use the JSON
object item[''id'']
Any idea?
new Ajax.Request(''/data.php'',{
method: ''post'',
onSuccess: function(transport){
var data = transport.responseText.evalJSON();
var items = data[''items''];
items.each(function(item) {
new Insertion.Top(''mydiv'', ''<div
id="''+item[''id'']+''"
style="display:none;"><div>''+item[''comment'']+''</div></div>'');
new Effect.SlideDown(item[''id'']);
}
}
});
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Gregory,
I believe the problem is in the way you''re passing id to
Effect.SlideDown
If we explicitly convert it to a string - everything works just fine.
var data =
''{"items":[{"id":9,"comment":"test
text"},{"id":12,"comment":"another
text"}]}''.evalJSON();
var blockTpl = new Template(''<div id=#{id}
style="display:none;"><div>#{comment}</div></div>'');
data.items.each(function(item){
new Insertion.Top(''myDiv'',
blockTpl.evaluate({
id: item.id,
comment: item.comment
})
)
Effect.SlideDown(item.id.toString());
})
--
View this message in context:
http://www.nabble.com/Insertion-%2B-Effect-%2B-JSON-Object-tf4253620.html#a12106238
Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Using item.id.toString() instead of item[''id''] did the trick. Thanks a lot! Greg On Aug 11, 10:09 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Gregory, > > I believe the problem is in the way you''re passing id to Effect.SlideDown > > If we explicitly convert it to a string - everything works just fine. > > var data = ''{"items":[{"id":9,"comment":"test > text"},{"id":12,"comment":"another text"}]}''.evalJSON(); > > var blockTpl = new Template(''<div id=#{id} > style="display:none;"><div>#{comment}</div></div>''); > > data.items.each(function(item){ > new Insertion.Top(''myDiv'', > blockTpl.evaluate({ > id: item.id, > comment: item.comment > }) > ) > Effect.SlideDown(item.id.toString()); > > }) > > -- > View this message in context:http://www.nabble.com/Insertion-%2B-Effect-%2B-JSON-Object-tf4253620.... > Sent from the RubyOnRails Spinoffs mailing list archive at Nabble.com.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---