Array for Object

20 views
Skip to first unread message

Eric Ponce

unread,
Apr 25, 2013, 10:25:57 AM4/25/13
to ged...@googlegroups.com
Hello!

With the new Geddy changes, i've need to changes all my Arrays for Objects.

I have one voting system for comments, with array its look like this:

Later Model -> Porperty PositiveVotes: Array
Now -> property Votes: Object

Later -> Votes has userIds like: PositiveVotes: [ 'id1', 'id2', 'id3', 'id4', 'id5' ] 
I used ".PUSH" -> comment.PositiveVotes.push( the new id ) and it works

Now with object, how can I put IDs and vote type into the object? I need some like this -> Votes: { {userId: 1, vote: 1} , { userId: 2, vote: 0 }, { userId: 3, vote: 1} }

How can I incrment the object withe the diferent user votes?

Thanks!!!!

Ag47

unread,
Apr 25, 2013, 3:45:03 PM4/25/13
to ged...@googlegroups.com
With the new Geddy changes, you have need to changes all your Arrays for Objects, but may be you can use array fields in objects:
Votes: {
  list: [ 'id1', 'id2', 'id3', 'id4', 'id5' ]
}
 and
comment.PositiveVotes.list.push( the new id )

On the other hand, if the user can vote only once for current comment then you can use userId as key for object and vote_type as value
Votes: { userId_1: vote_type_1, userId_2 : vote_type_1 }
for adding element:
comment.Votes[ userId_1 ] = vote_type_1;
before this you can check user vote for current user
if ( typeof  comment.Votes[ userId_1 ] === 'undefined' ) {}

der_On

unread,
Apr 26, 2013, 4:29:16 AM4/26/13
to ged...@googlegroups.com
You shouldn't need to make objects out of your array properties. The new geddy simply makes a JSON out of any object (and arrays are actually objects in JS) and then it converts it back from JSON.

Eric Ponce

unread,
Apr 26, 2013, 12:28:44 PM4/26/13
to ged...@googlegroups.com
Thanks Ag47 and der_On, it works fine!
Reply all
Reply to author
Forward
0 new messages