Debugging object in JSON notation
I've been trying to find a good way to debug in Titanium Mobile, but ran into some issues.
Whenever I debug my object, all I get is "object" and the object Type (e.g. [object TiUITableView]). I would however like to see its contents in a JSON format. If I try:
Titanium.API.debug(JSON.stringify(items));
All I get is an empty object ({}) while I'm sure something's in there. (I have also tried it with Titanium.UI.currentWindow which also returns {})
Is there any way to achieve this?
Eternal gratitude to he who relieves me from this agony…
3 Answers
-
Accepted Answer
Ok - I've revisited the code and pushed the envelope a little harder.
You can find the result - http://gist.github.com/465256
An example of using it is:
// I've tried to catch every error but you never know :) try { dumpObj2(items, true, true); } catch (e) { // Wussup doc? debug(e.message); }
As you'll see from the gist
- the first arg is what you want to debug
- the second arg is a flag (true|false) saying if you want deep information or not
- the last arg is a flag (true|false) saying if you want funcs included
-
Update2: see this gist instead: http://gist.github.com/465256
-
Unfortunately I cannot get this working with ANY Titanium object. If I make my own object, it works fine, but any Titanium object does not get into the for loop. It's as if there are no properties.
I have tried the following:
var tableItems = [{title: 'Pagina 1'},{title: 'Pagina 2'},{title: 'Pagina 3'}];
var items = Titanium.UI.createTableView(
{ data:tableItems,
width: 200,
position: 'absolute',
rowHeight: 100,
rowCount: tableItems.length
}
);dumpObject(items);
But gives me no result whatsoever… (and yes it does call the function :-) )