Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Optimize my code to display rows in section ?

$
0
0

Hi,

I want to create a table with different sections and rows in each sections.

My data comes from a collection.

Here is a code that can display section + row. The display time is correct but I do not have the desired result because i have always section + rows.

var tableData = [];
var section = [];
 
var events = Alloy.Collections.event;
events.fetch({'success':function(collection,response){
    _.each(response, function(value, key){
        var start = value.start;
 
        section = Ti.UI.createTableViewSection({
            headerTitle : value.starttext
        });
 
        var row = Alloy.createController('agenda_row', value).getView();
        section.add(row);
        tableData.push(section);
    });
 
    $.agenda.setData(tableData);
}});
This code below does exactly what I want but the display time is two to three times longer! Is it just my array ? Do you see how to optimize this code?
var tableData = [];
var section = [];
 
var events = Alloy.Collections.event;
events.fetch({'success':function(collection,response){
    //Ti.API.info(JSON.stringify(response));
 
 
    _.each(response, function(value, key){
        var start = value.start;
 
        if(typeof section[start] != 'object'){
            section[start] = Ti.UI.createTableViewSection({
                headerTitle : value.starttext
            });
        }
 
        var row = Alloy.createController('agenda_row', value).getView();
        section[start].add(row);
    });
 
    _.each(section, function(value, key){
        tableData.push(value);
    });
 
    $.agenda.setData(tableData);
}});
Thank you.

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>