Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10424] MobileWeb: TableView scroll event receiving circular data structure

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Fix
Resolution Date2012-11-28T02:59:02.000+0000
Affected Version/sRelease 2.1.1
Fix Version/sn/a
ComponentsMobileWeb
Labelsn/a
ReporterArthur Evans
AssigneeIngo Muschenetz
Created2012-08-13T13:38:15.000+0000
Updated2014-01-28T23:23:13.000+0000

Description

When trying to decode tableview scroll events using JSON.stringify, I eventually receive the exception: Uncaught type error: trying to convert circular structure to JSON. I am not seeing this on any other platform. Test code:

var win = Ti.UI.createWindow({
	backgroundColor: 'black',
	exitOnClose: true,
	fullscreen: false,
	title: 'TableView Demo'
});

var defaultFontSize = Ti.Platform.name === 'android' ? 16 : 14;
var tableData = [];

for (var i=1; i<=20; i++){
	var row = Ti.UI.createTableViewRow({
		className:'forumEvent',
		selectedBackgroundColor:'white',
		height:110,
		title:'Row ' + i
	});

	tableData.push(row);
}

var tableView = Ti.UI.createTableView({
	backgroundColor:'white',
	data:tableData
});
tableView.addEventListener('scroll', function(evt){
	Ti.API.info("Got event type[" + evt.type + "]: " + JSON.stringify(evt, function(key, value) {
		if(key === 'source' || key === 'type') {
			return undefined;
		} else {
			return value;
		}

	}, 2));});

win.add(tableView);
win.open();

Comments

  1. Bryan Hughes 2012-08-13

    UI controls have to have cyclic data structures for performance reasons. Namely each control must know who it's parents are, and who its children are, meaning that a parent points to its child who points to its parent who points to its child, ad nauseum.
  2. Arthur Evans 2012-08-14

    This may be crazy, but couldn't we add a toJSON method to View or Element that omits any properties starting with underscore? I realize it's not absolutely necessary, but not crashing when someone calls stringify on an event object would be a good thing.
  3. Neeraj Gupta 2012-08-14

    Reopening this bug as we should evaluate the possible alternate implementations. It does not look right when it works on other platforms but crashes on Mobile Web platform.
  4. Chris Barber 2012-11-28

    We aren't going to fix this. You cannot JSON.stringify UI elements. They reference parent and child nodes which would be a massive undertaking to re-architect Mobile Web to make JSON.stringify happy.

JSON Source