jquery ajax call to rails not returning an array when one record returns -
the problem have when make ajax call, , there more 1 record, array returned , can call list[0] or whatever first. if make same call , receive single object object rather array of one.
any ideas how can handle this?
update: used these functions
function isarray(obj) { return (obj.constructor.tostring().indexof("array") != -1); }
function getarray(obj) {
if(obj.constructor.tostring().indexof("array") != -1){ return obj; } else { var myarr = [1]; myarr[0]=obj; return myarr; } }
you check javascript:
if ( list.length > 1 ) { list[0]; } else { list; } you on server side:
@entries = [@entries] unless @entries.is_a?(array)
Comments
Post a Comment