How to access @rid, @type etc in client JS

141 views
Skip to first unread message

Gaurav Dhiman

unread,
Mar 10, 2014, 6:22:21 AM3/10/14
to orient-...@googlegroups.com
Issue - @ character is not a valid character in JavaScript identifier (variable, function name etc), then how to refer @rid in returned JSON from OrientDB ?

Details:

When I get the JSON response from OrientDB and I try to show the @rid, @type etc in app, I get JS error

In client http response function, below is the wrong syntax
function httpResponse (data, status) {
   alert(data.result[0].@rid);                     // how to refer @rid here ??
}

Luca Garulli

unread,
Mar 10, 2014, 7:12:42 AM3/10/14
to orient-database

Hi,
Use ['@rid']

Lvc@

Sent from Mobile device

--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gaurav Dhiman

unread,
Mar 10, 2014, 9:33:06 AM3/10/14
to orient-...@googlegroups.com
@Lvc, as suggested by you, when I use ['@rid']
alert(data.result[0].['@rid']);

Chrome debugger says "Uncaught SyntaxError: Unexpected string"

Any other suggestions. I am sure many other OrientDB users must have faced this basic thing while consuming OrientDB generated JSON in their app.

Can not we configure OrientDB to use some other character in place of @ and # while throwing out JSON to client ?


Regards,
Gaurav



--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/cieTooNWJms/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

Julien L.

unread,
Mar 10, 2014, 10:36:43 AM3/10/14
to orient-...@googlegroups.com
The dot notation is the shortcut of the array access. Just use data.result[0]['@rid'] in this case.

Gaurav Dhiman

unread,
Mar 10, 2014, 10:59:53 AM3/10/14
to orient-...@googlegroups.com
Thanks Julien, it worked.
Can we refer deep level objects in this manner, using array notation [] in place of dot notation ?

Thanks for your help !

Regards,
Gaurav


Julien L.

unread,
Mar 10, 2014, 11:18:23 AM3/10/14
to orient-...@googlegroups.com
Yes, you can. These two notations are exactly the same : a.b.c.d.e.f <=> a['b'].c['d']['e'].f

The array notation is very usefull when you have dynamic keys (arr[dynamicKey]) or complex keys (arr['Hey dude !'])
Reply all
Reply to author
Forward
0 new messages