I'm triying to fetch a collection with network disabled and doesn't work, page doesn't load the rows. Can someone help me with this?
My code:
var args = arguments[0] || {}; var rootsCollection = Alloy.Collections.sqlroots; function itemTransform(item){ Ti.API.info("item", item.title); for(var prop in item){ Ti.API.info(prop); } var transformedItem = { title: item.name, id: item.id, hasChild: true }; // PERSONALIZACIÓN DE FILAS var row = Ti.UI.createTableViewRow({ id: item.id, objName: 'row', touchEnabled: true, hasChild: true, height: 50 }); row.add(Ti.UI.createImageView({ /* // Para colocar icono image: item.icon, left: -10, height: 30, width: "auto" */ })); row.add(Ti.UI.createLabel({ objName: 'label', text: item.name, color: "#404245", //textAlign: Ti.UI.TEXT_ALIGNMENT_LEFT, // devuelve 0, y no tiene efecto en la alineación left: 14, // left 14 para alinear a la izquierda sin icono, 44 cuando icono font: { fontSize: "17dp", fontFamily: 'Helvetica Neue', lineHeight: "22dp" } })); return row; // END PERSONALIZACIÓN DE FILAS } function doRootClick(e){ Alloy.Globals.idRoot = e.rowData.id; var controller = Alloy.createController('gama'); var view = controller.getView(); Alloy.CFG.navgroup.open(view); } if(Ti.Network.online){ var sqlRoots = Alloy.Collections.sqlroots; sqlRoots.reset(); Alloy.Collections.roots.fetch({ success: function(dummy, data) { _.each(data, function(item) { for (var itemProp in item){ Ti.API.info(itemProp); } Ti.API.info("item title", item.name); var root = Alloy.createModel("sqlroots",{ name: item.name, id: item.id, description: item.description, icon: item.icon, }); Alloy.Collections.roots.add(root); root.save(); rootsCollection.fetch(); }); } }); } rootsCollection.fetch(); rootsCollection.on('fetch', function (e) { var collectionData = []; var models = rootsCollection.toJSON(); models.each(function(item){ var transFormedData = itemTransform(item); collectionData.push(transFormedData); }); $.rootsTable.setData(collectionData); });