I am running some logic in the method posted below that works fine in a desktop browser but returns an undefined value in the device/simulator. I'm thinking this is some kind of race condition, but maybe someone can shine a light as to why I am seeing this inconsistent behavior. All of this is popping off when someone clicks on a dataview item.
Code:
onArticleSelect: function(view, record, eOpts) {
var store = view.getStore(),
first = store.first(),
recordId = record.getId(),
storeId = store.getStoreId().toString(),
sectionRaw = storeId.replace(/([A-Z])/g, ' $1'),
sectionTitle = sectionRaw.replace(/^\s+|\s+$/g, ""),
articleCarousel = this.getArticleCarousel(),
articlePanel = this.getArticlePanel(),
article = this.getArticle(),
//articleId = articleCarousel.getActiveItem().getId(),
dashboardPanel = this.getDashboardPanel(),
dashboard = this.getDashboard(),
splash = this.getSplash(),
dashboardCarousel = this.getDashboardCarousel(),
storeItems = storeId+'Items',
articleSection = this.getArticleSection(),
viewIdReplace = view.getId().replace(/Feed$/g, ''),
items = [];
view.deselectAll();
if(articleCarousel.items.length !== 0) {
console.log(articleCarousel.items.length); //returns length properly in desktop browser and simulator/device
console.log(articleCarousel.getActiveItem().sid); //returns sid property in desktop browser but returns undefined on simulator/device
console.log(articleCarousel.getActiveItem().id); //returns id property in desktop browser and simulator/device
console.log(viewIdReplace); //returns properly on both desktop browser and device
}
if(articleCarousel.items.length === 0) {
console.log('initializing all articles...');
console.log('store: ', store);
//articleCarousel.setMasked(true);
store.each(function(rec, offset) {
var recId = rec.data.articleId.toString(),
storeName = store.getStoreId();
items.push(Ext.create('TheStreet.view.Article', {
sid: storeName,
record: rec,
id: recId
}));
});
articleCarousel.setItems(items);
//articleCarousel.setMasked(false);
} else if ((articleCarousel.items.length !== 0) && (articleCarousel.getActiveItem().sid !== viewIdReplace)) {
console.log('replacing all articles...');
articleCarousel.removeAll();
//articleCarousel.setMasked(true);
store.each(function(rec, offset) {
var recId = rec.data.articleId.toString(),
storeName = store.getStoreId();
items.push(Ext.create('TheStreet.view.Article', {
sid: storeName,
record: rec,
id: recId
}));
});
articleCarousel.setItems(items);
//articleCarousel.setMasked(false);
}
articleSection.setHtml('<h4>News :: '+sectionTitle+'</h4>');
dashboardPanel.hide(true);
articlePanel.show(true);
articleCarousel.setActiveItem(Ext.getCmp(record.data.articleId.toString()));
}