Processing JSON object lists with Mootools Hash

12 views
Skip to first unread message

focusfriend

unread,
Feb 15, 2008, 7:58:14 AM2/15/08
to Appcelerator Platform SDK
For processing JSON object lists I'm using the new Mootools Hash:

http://docs12b.mootools.net/Native/Hash
http://mootools.net/download/tags/1-2b2 (select only "native: hash")

But there seems to be a conflict with Appcelerator, since the
Hash.each() method not only lists the object list itself, but also all
the Hash methods. Try this:


<app:script>

var persons = new Hash([{firstname:'john',name:'doe'},
{firstname:'mary',name:'may'}]);

persons.each( function(value, key) {
Logger.info(key + " " + value);
});
</app:script>

And you get this:

0 [object Object]

1 [object Object]

eachSlice function (D, C, B) { C = C ? C.bind(B) : Prototype.K; var A
= - D, E = [], F = this.toArray(); while ((A += D) < F.length)
{ E.push(F.slice(A, A + D)); } return E.collect(C, B); }

all function (C, B) { C = C ? C.bind(B) : Prototype.K; var A = true;
this.each(function (E, D) {A = A && !!C(E, D);if (!A) {throw
$break;}}); return A; }

any function (C, B) { C = C ? C.bind(B) : Prototype.K; var A = false;
this.each(function (E, D) {if (A = !!C(E, D)) {throw $break;}});
return A; }

...

Jeff Haynie

unread,
Feb 15, 2008, 10:34:01 AM2/15/08
to appcelerator...@googlegroups.com
Yeah, you gotta love some of the Object prototype collusion inside of Prototype. Prototype attaches a bunch of stuff to the object.prototype so this is the side effect.

You could probably check to make sure it's not a function in your iterator:


  persons.each( function(value, key) {
   if (!Object.isFunction(key)) Logger.info(key + " " + value);
 });
--
Jeff Haynie
http://blog.jeffhaynie.us

focusfriend

unread,
Feb 15, 2008, 10:55:19 AM2/15/08
to Appcelerator Platform SDK

Does Appcelerator have fancy JSON object/hash processing features by
itself?

-Ivo

On 15 feb, 16:34, "Jeff Haynie" <jhay...@gmail.com> wrote:
> Yeah, you gotta love some of the Object prototype collusion inside of
> Prototype. Prototype attaches a bunch of stuff to the object.prototype so
> this is the side effect.
>
> You could probably check to make sure it's not a function in your iterator:
>
>   persons.each( function(value, key) {
>    if (!Object.isFunction(key)) Logger.info(key + " " + value);
>  });
>
>
>
> On Fri, Feb 15, 2008 at 7:58 AM, focusfriend <focusfri...@gmail.com> wrote:
>
> > For processing JSON object lists I'm using the new Mootools Hash:
>
> >http://docs12b.mootools.net/Native/Hash
> >http://mootools.net/download/tags/1-2b2(select only "native: hash")

Mark Luffel

unread,
Feb 15, 2008, 12:07:05 PM2/15/08
to appcelerator...@googlegroups.com
Yeah, we include the Prototype library by default, and it includes tools for using "hashes"


Some of methods have different names, but the functionality looks equivalent. A brief google for "mootools prototype" suggests that they step on each other's toes and can't be used in the same file.

--Mark

Jeff Haynie

unread,
Feb 15, 2008, 3:15:32 PM2/15/08
to appcelerator...@googlegroups.com
yes - we use prototype internally.

You can do:

Object.toJSON(object)

or

string.evalJSON()

on any string to convert it to json.



On Fri, Feb 15, 2008 at 10:55 AM, focusfriend <focus...@gmail.com> wrote:

sascha....@gmail.com

unread,
Feb 15, 2008, 4:03:24 PM2/15/08
to Appcelerator Platform SDK

Yep, I ditched MooTools and are now back to native Prototype. Do you
walk in sync with the latest Prototype release (1.6.0.2)?

-Ivo

On 15 feb, 18:07, "Mark Luffel" <markluf...@gmail.com> wrote:
> Yeah, we include the Prototype library by default, and it includes tools for
> using "hashes"http://www.prototypejs.org/api/hash
>
> Some of methods have different names, but the functionality looks
> equivalent. A brief google for "mootools prototype" suggests that they step
> on each other's toes and can't be used in the same file.
>
> --Mark
>
> On Fri, Feb 15, 2008 at 10:55 AM, focusfriend <focusfri...@gmail.com> wrote:
>
> > Does Appcelerator have fancy JSON object/hash processing features by
> > itself?
>
> > -Ivo
>
> > On 15 feb, 16:34, "Jeff Haynie" <jhay...@gmail.com> wrote:
> > > Yeah, you gotta love some of the Object prototype collusion inside of
> > > Prototype. Prototype attaches a bunch of stuff to the object.prototypeso
> > > this is the side effect.
>
> > > You could probably check to make sure it's not a function in your
> > iterator:
>
> > >   persons.each( function(value, key) {
> > >    if (!Object.isFunction(key)) Logger.info(key + " " + value);
> > >  });
>
> > > On Fri, Feb 15, 2008 at 7:58 AM, focusfriend <focusfri...@gmail.com>
> > wrote:
>
> > > > For processing JSON object lists I'm using the new Mootools Hash:
>
> > > >http://docs12b.mootools.net/Native/Hash
> > > >http://mootools.net/download/tags/1-2b2(selectonly "native: hash")

te...@vijedi.net

unread,
Feb 15, 2008, 5:14:23 PM2/15/08
to appcelerator...@googlegroups.com
We're currently on 1.6.0.  We do try to keep up with the latest prototypes, depending on compatibility and our release cycle.

Tejus Parikh
Software Developer
Appcelerator, Inc
Reply all
Reply to author
Forward
0 new messages