Results 1 to 9 of 9

Thread: Having problem to set setStore dynamially

  1. #1

    Default Having problem to set setStore dynamially

    Version :- Sencha Touch 2.2.1

    I am not able to set setStore from the controller. When I call setStore then it give me an error "
    Uncaught TypeError: Object [object Object] has no method 'setStore'
    "

    Here are my code:-

    app.js

    Code:
    var feedURL = 'http://localhost:1449/Dummyorganiser/';
    
    Ext.application({
        name: 'EventOrganiser',
        stores: ['Players'],
        models: ['Player'],
        views: ['MyAddressBook'],
        controllers: ['MyAddressBook'],
    
        launch: function() {
                   Ext.Viewport.add([
                { xtype: 'myaddressbookview' }
            ]);
        }
    });

    data.json

    Code:
    {
        "players":
            [
                { "playerId": "5001", "firstName": "None", "lastName": "None", "sex": "Male" },
                { "playerId": "5002", "firstName": "Glazed", "lastName": "None", "sex": "Male" },
                { "playerId": "5005", "firstName": "Sugar", "lastName": "None", "sex": "Male" },
                { "playerId": "5007", "firstName": "Powdered Sugar", "lastName": "None", "sex": "Male" },
                { "playerId": "5006", "firstName": "Chocolate with Sprinkles", "lastName": "None", "sex": "Male" },
                { "playerId": "5003", "firstName": "Chocolate", "lastName": "None", "sex": "Male" },
                { "playerId": "5004", "firstName": "Maple", "lastName": "None", "sex": "Male" }
            ]
    }

    app/controller/MyAddressBook.js

    Code:
    Ext.define('EventOrganiser.controller.MyAddressBook', {
        extend: 'Ext.app.Controller',
        config: {
            refs: {
                myAddressBookView: 'myaddressbookview',
                myAddressBookList: '#myAddressBookList'
            },
            control: {
                myAddressBookView: {
                    initialize: 'initialize'
                }
            }
        },
        initialize: function() {
            var playersStore = Ext.getStore('Players');
            this.getMyAddressBookList().setStore(playersStore);
            playersStore.load();
        }
    });
    app/view/MyAddressBook.js

    Code:
    Ext.define('EventOrganiser.view.MyAddressBook', {
        extend: 'Ext.NavigationView',
        xtype: 'myaddressbookview',
        alias: 'widget.myaddressbookview',
        
        //    initialize: function() {
        //        alert("init");
        //    }
        config: {
        
            items: [{
            xype: 'list',
            id: 'myAddressBookList',
            store: 'Players',
                itemId: 'myAddressBookList',
                listConfig: {
                    plugins: [{
                        xclass: 'Ext.plugin.ListPaging',
                        autoPaging: true
    }]
                    },
                    itemTpl: '<div class="myContent">' +
                            '<div>First name <b>{firstName}</b></br>' +
                            'Last name: <b>{lastName}</b><br/> Sex: <b>{sex}</b></div>' +
                        '</div>'
    }]
                }
            });

    app/model/Player.js

    Code:
    Ext.define('EventOrganiser.model.Player', {
        extend: 'Ext.data.Model',
    
        config: {
            idProperty: 'playerId',
            fields: ['playerId', 'firstName', 'lastName', 'sex']
        }
    });

    app/store/Players.js

    Code:
    Ext.define('EventOrganiser.store.Players', {
        extend: 'Ext.data.Store',
        requires: ['EventOrganiser.model.Player'],
        config: {
            model: 'EventOrganiser.model.Player',
            //autoLoad: true,
            proxy: {
                type: 'ajax',
                url: feedURL + 'data.json',
                pageParam: 'page',
                limitParam: '',
                startParam: '',
                extraParams: {
                    limit: 10,
                    source: ''
                },
                reader: {
                    type: 'json',
                    rootProperty: 'players',
                    totalProperty: 'total'
                }
            },
            listeners: {
                load: function(store, records, success, operation, args) {
                     
                    }
                }
            }
        }
    });
    Please help me.

  2. #2
    Sencha User
    Join Date
    Jan 2011
    Posts
    134
    Answers
    6

    Default Try putting break to see if the list is being selected

    Hi
    I would suggest putting a debugger statement - after setStore command. I am not sure if the list is being selected.
    PHP Code:

    Ext
    .define('EventOrganiser.controller.MyAddressBook', {    extend'Ext.app.Controller',    config: {        refs: {            myAddressBookView'myaddressbookview',            myAddressBookList'#myAddressBookList'        },        control: {            myAddressBookView: {                initialize'initialize'            }        }    },    initialize: function() {        var playersStore Ext.getStore('Players');        this.getMyAddressBookList().setStore(playersStore);debugger//check if the above statement is selecting the list        playersStore.load();    } }); 

  3. #3

    Default

    When I debug my program on that line and see the this.getMyAddressBookList() property so i can not find any setStore method but i can see setData and setRecord method.

    Please help me.

  4. #4
    Sencha User
    Join Date
    Jan 2011
    Posts
    134
    Answers
    6

    Default Check the returned object

    Try adding this
    var tempObj = this.getMyAddressBookList();
    debugger

    See if the tempObj is the list object - I suspect it is not that is why you don't have access to the setStore method.

    Hope this helps

  5. #5

    Default

    how to check that it is a Ext.List or have some other component?

  6. #6

    Default

    If I try like this:-

    this.getMyAddressBookList().getXTypes();

    it is given me "component/container".

  7. #7
    Sencha User
    Join Date
    Jan 2011
    Posts
    134
    Answers
    6

    Default Check in the console

    The debugger statement will break the code execution. Then in the console - type in tempObj and it will list all the properties and methods of the object.

    There is a video on youtube (3 videos) Rohit Ghatol about using Sencha touch it might be worth it for you to take a couple of hours and to view those videos. He does a very good job explaining creating an application in Sencha Touch. I would recommend watching them.

  8. #8

    Default

    I even tries like this but does not work:-

    Code:
     xype: 'list',
                listeners: {
                    initialize: function() {
                        
                      var playersStore = Ext.getStore('Players');
                                          this.setStore(playersStore);
                                          playersStore.load();
                        console.log(this);
                    }
                },

  9. #9
    Sencha User
    Join Date
    Apr 2012
    Posts
    164
    Answers
    13

    Default

    You need to include the reference to your stores at the top of your controller class that calls your stores.

    Simply move
    Code:
    stores: ['Players'],
    from Ext.Application to the controller.

Posting Permissions

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