This doesn't work as expected. Table ends up empty. Am I doing something wrong?
APP.JSTi.UI.backgroundColor = 'white';
var win = Ti.UI.createWindow();
var table = Ti.UI.createTableView({
data: [{"title": "Apples"},{"title": "Bananas"},{"title": "Carrots"},{"title": "Potatoes"}]
});
win.add(table);
win.open();
win.addEventListener('click', function(e) {
table.setData(JSON.parse(JSON.stringify(table.getData())));
alert(table.data);
});
2 Answers
Remove the quotes from title :.
It get's weirder. Put a breakpoint on line 39 of the code below. Then just run it in the iPhone simulator. Not in debug mode. Just run it. TextArea shows []. Now run it in the debugger, and when it breaks, just resume (F8) and the TextArea will have: [{"headerTitle":"Fruit"},{"headerTitle":"Vegetables"}]
Ti.UI.backgroundColor = 'white'; var win = Ti.UI.createWindow({ layout : 'vertical' }); var sectionFruit = Ti.UI.createTableViewSection({ headerTitle : 'Fruit' }); var row1 = Ti.UI.createTableViewRow({ title : 'Apples' }); var row2 = Ti.UI.createTableViewRow({ title : 'Bananas' }); sectionFruit.add(row1); sectionFruit.add(row2); var sectionVeg = Ti.UI.createTableViewSection({ headerTitle : 'Vegetables' }); var row3 = Ti.UI.createTableViewRow({ title : 'Carrots' }); var row4 = Ti.UI.createTableViewRow({ title : 'Potatoes' }); sectionVeg.add(row3); sectionVeg.add(row4); var table = Ti.UI.createTableView({ height : Ti.UI.SIZE, data : [sectionFruit, sectionVeg] }); win.add(table); var textarea = Ti.UI.createTextArea({ height: 300 }); win.add(textarea); textarea.value = JSON.stringify(table.data); // <<< put breakpoint here win.open();
Your Answer
Think you can help? Login to answer this question!