[TIMOB-10424] MobileWeb: TableView scroll event receiving circular data structure
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2012-11-28T02:59:02.000+0000 |
Affected Version/s | Release 2.1.1 |
Fix Version/s | n/a |
Components | MobileWeb |
Labels | n/a |
Reporter | Arthur Evans |
Assignee | Ingo Muschenetz |
Created | 2012-08-13T13:38:15.000+0000 |
Updated | 2014-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();
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.
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.
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.
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.