Results 1 to 2 of 2

Thread: Store looping is not working inside the load function

  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    30
    Vote Rating
    0
      0  

    Question Store looping is not working inside the load function

    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
    -----------------
    Code:
    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
    -------------
    Code:
    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
    ------------------------
    Code:
    
    {"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....

  2. #2
    Sencha - Services Team AndreaCammarata's Avatar
    Join Date
    Jun 2009
    Location
    Italy
    Posts
    1,395
    Vote Rating
    24
      0  

    Default

    Hi.
    Your load callback function returns you the loaded records.
    Did you try to loop on those?
    If you show an alert just before to loop the store, is it shown?
    Sencha Inc
    Andrea Cammarata, Solutions Engineer
    Owner at SIMACS

    @AndreaCammarata
    www.andreacammarata.com
    github: https://github.com/AndreaCammarata

    TUX components bundle for Sencha Touch 2.x.x
    https://github.com/AndreaCammarata/TUX


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •