Forum: Rails Spinoffs (closed, excessive spam) I need an advise

Posted by buda (Guest)
on 2008-06-24 20:21
(Received via mailing list)
I work with JSON property like Obj which might be null, a single
oblect or a collection of objects
Every time I must analize

if (req.responseJSON.Obj == null){
  ....
}

if (req.responseJSON.Obj && !req.responseJSON.Obj.length){
  ... ia a single instanse
}

if (req.responseJSON.Obj && req.responseJSON.Obj.length){
   req.responseJSON.Obj.each(....)
}

but I want to do with resul in the same manner
   req.responseJSON.Obj.each(....)

if I use $A(req.responseJSON.Obj) it doesnt represent a single
instanse as an array and how should I do it ?
Help me please
Posted by kangax (Guest)
on 2008-06-24 22:27
(Received via mailing list)
...
var object = req.responseJSON.Obj,
      array = Object.isArray(object) ? object : [object];
...
array.each( ... )
...

- kangax
Posted by buda (Guest)
on 2008-06-25 07:55
(Received via mailing list)
Thankth kagnax
And whence only you know all? :)
This topic is locked and can not be replied to.