pm.sreejith
11 Nov 2011, 12:32 AM
Hi All,
I am trying to loop the items returned from the store. please go through the code given below it having any issues. Also I'm getting the Json response from server successfully.
Controller
-----------------
Ext.define('Sencha.controller.Main', {
extend: 'Ext.app.Controller',
stores: [
'Mains', 'Contentlist', 'Latestarticles', 'ArticleCategoryWise'
],
views: ['Home', 'Products', 'Contact', 'Article','LatestArticles','ContentList', 'ContentCarousel'],
refs: [
{
ref: 'contactForm',
selector: '#contactForm'
},
{
ref: 'contentList',
selector: 'contentlist'
},
{
ref: 'contentCarousel',
selector: 'contentcarousel'
},
{
ref: 'articleCategoryWise',
selector: 'ArticleCategoryWise'
}
],
init: function() {
this.control({
'button[action=submitContact]': {
tap: 'submitContactForm'
},
'contentlist': {
select: this.onGetLatestArticles
}
});
this.getArticles(0);
},
submitContactForm: function() {
var form = this.getContactForm();
form.submit({
url: 'contact.php'
});
},
onGetLatestArticles: function(list,category){
iCategoryId = category.get('categoryid');
this.getArticles(iCategoryId);
/*
var carItems = [];
carItems.push({
html: '<img src="http://static.icc-cricket.yahoo.net/ugc/images/DAB0CAA87C80E06A0E0279448E462AAA_1259662727486_802.jpg" alt="no image" width=395 height=600</img>',
});
this.getContentCarousel().setItems(carItems);*/
},
getArticles:function(iCatId){
articleCatWise = this.getArticleCategoryWiseStore();
articleCatWise.clearFilter();
articleCatWise.filter([{property: 'catId',value: iCatId}]);
articleCatWise.load({
scope : this,
callback: function(records, operation, success) {
var arrArticleItems = [];
var carouselItems = [];
var carouselSubItems = [];
var iCnt = 0;
//the operation object contains all of the details of the load operation
articleCatWise.each(function(rec){
Ext.Msg.alert("Arr Length", "Inside Loop", function(){});
});
Ext.Msg.alert("Arr Length", "After Loop", function(){});
}
});
}
});
Store
-------------
Ext.define('Sencha.store.ArticleCategoryWise', {
extend : 'Ext.data.Store',
xtype: 'ArticleCategoryWise',
model : 'Sencha.model.ArticleCategoryWise',
requires: ['Sencha.model.ArticleCategoryWise'],
filters: [{
property: 'catId',
value: 0
}],
proxy : {
type : 'ajax',
url : 'getarticlescategorywise.php',
reader : {
type : 'json',
root : 'articles',
totalCount : 'total'
}
},
autoLoad: true
});
Json Response
------------------------
{"success":true,"total":1,"articles":[{"articleid":12,"articletitle":"Test Title","articledate":"November 11 2011","articleshortdesc":"Test Description","articleimg":"Test Image"}]}
I'm developing by using ST2.0 with MVC pattern.
Any help would be appreciated....
I am trying to loop the items returned from the store. please go through the code given below it having any issues. Also I'm getting the Json response from server successfully.
Controller
-----------------
Ext.define('Sencha.controller.Main', {
extend: 'Ext.app.Controller',
stores: [
'Mains', 'Contentlist', 'Latestarticles', 'ArticleCategoryWise'
],
views: ['Home', 'Products', 'Contact', 'Article','LatestArticles','ContentList', 'ContentCarousel'],
refs: [
{
ref: 'contactForm',
selector: '#contactForm'
},
{
ref: 'contentList',
selector: 'contentlist'
},
{
ref: 'contentCarousel',
selector: 'contentcarousel'
},
{
ref: 'articleCategoryWise',
selector: 'ArticleCategoryWise'
}
],
init: function() {
this.control({
'button[action=submitContact]': {
tap: 'submitContactForm'
},
'contentlist': {
select: this.onGetLatestArticles
}
});
this.getArticles(0);
},
submitContactForm: function() {
var form = this.getContactForm();
form.submit({
url: 'contact.php'
});
},
onGetLatestArticles: function(list,category){
iCategoryId = category.get('categoryid');
this.getArticles(iCategoryId);
/*
var carItems = [];
carItems.push({
html: '<img src="http://static.icc-cricket.yahoo.net/ugc/images/DAB0CAA87C80E06A0E0279448E462AAA_1259662727486_802.jpg" alt="no image" width=395 height=600</img>',
});
this.getContentCarousel().setItems(carItems);*/
},
getArticles:function(iCatId){
articleCatWise = this.getArticleCategoryWiseStore();
articleCatWise.clearFilter();
articleCatWise.filter([{property: 'catId',value: iCatId}]);
articleCatWise.load({
scope : this,
callback: function(records, operation, success) {
var arrArticleItems = [];
var carouselItems = [];
var carouselSubItems = [];
var iCnt = 0;
//the operation object contains all of the details of the load operation
articleCatWise.each(function(rec){
Ext.Msg.alert("Arr Length", "Inside Loop", function(){});
});
Ext.Msg.alert("Arr Length", "After Loop", function(){});
}
});
}
});
Store
-------------
Ext.define('Sencha.store.ArticleCategoryWise', {
extend : 'Ext.data.Store',
xtype: 'ArticleCategoryWise',
model : 'Sencha.model.ArticleCategoryWise',
requires: ['Sencha.model.ArticleCategoryWise'],
filters: [{
property: 'catId',
value: 0
}],
proxy : {
type : 'ajax',
url : 'getarticlescategorywise.php',
reader : {
type : 'json',
root : 'articles',
totalCount : 'total'
}
},
autoLoad: true
});
Json Response
------------------------
{"success":true,"total":1,"articles":[{"articleid":12,"articletitle":"Test Title","articledate":"November 11 2011","articleshortdesc":"Test Description","articleimg":"Test Image"}]}
I'm developing by using ST2.0 with MVC pattern.
Any help would be appreciated....