Results 1 to 4 of 4

Thread: General questions about object creation

  1. #1

    Question General questions about object creation

    Hello all,
    I'm new to Sencha Touch, i come from iOS and Java development and i'm a bit confuse with object creation and management.
    I try create something like a 'gridView' (to understand how sencha works). So in other language
    I would have created a 'gridItem' which take an 'name' and an 'id', and a gridView which manage all given gridItems. gridView also handle click action on an item on dispatch event to another object.

    So i'have made this : (GridItem are displayed but i can't set a listener on them)

    GridItem.js

    Code:
    Ext.define('SenchaTry.view.GridItem',{
        extend:'Ext.Container',
        xtype:'gridItem',
        requires:[
            'Ext.Label',
        ],
        config:{
            id:null,
            title:null,
            img:null,
            action:null,
            style:'width:30%;background:red;height:30%',
            items:[
                {
                    xtype:'label',
                    html:'Label1',
                }
            ]
        },
    });
    GridView.js

    Code:
    Ext.define('SenchaTry.view.GridView',{
        extend:'Ext.Container',
        xtype:'gridView',
        gridItems:null,    
        config:{
            width: 350,
            height: 370,
            style:'with:100%;background:blue;height:30%',
            listeners: {
                painted: function () {
                        console.log("Count : "+this.gridItems.length);
                    for(var i = 0; i< this.gridItems.length;i++){
                        gridItem = this.gridItems[i];
                        gridItem.on('tap', this.handleTap, this,{
                            single:true
                        });
                    }
                        this.setItems(this.gridItems);
                }
            },
            items:[
                {
                    xtype:'label',
                    html:'qsdqsd'
                }
            ]
        }
    })

    And the Main.js

    Code:
    Ext.define("SenchaTry.view.Main", {
        extend: 'Ext.Panel',
        requires: [
            'Ext.TitleBar',
        ],
        
        config: {
            tabBarPosition: 'bottom',
    
    
            items: [
                {
                    xtype:'gridView',
                    gridItems:[
                        {xtype:'gridItem',id:'firstItem'
                        },
                        {
                            xtype:'gridItem',
                            id:'secItem'
                        },
                        {
                            xtype:'gridItem',
                            id:'thridItem'
                        }
                    ]
                }
            ]
        }
    });
    Many thanks for your explanations

    (i will go to re-read the doc)

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,451

    Default

    Since the SenchaTry.view.Main class is going to be your main view you can create it using:

    Code:
    new SenchaTry.view.Main({
        fullscreen : true 
    });
    or

    Code:
    Ext.create('SenchaTry.view.Main', {
        fullscreen : true
    });
    I would stay away from using id as you can easily run into collisions if you have duplicate id.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Fullstack Engineer
    ________________
    Modus Create is based on the model of an open source team. We’re a remote, global team of experts in our field. To find out more about the work we do, head over to our website.

    Check out my GitHub:
    https://github.com/mitchellsimoens

  3. #3

    Default

    Hi,

    I don't have problem to load the main, only to catch action on GridItem.

    Thanks for your reply

    Ben

  4. #4
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,451

    Default

    You don't have any listeners in the grid item class.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Fullstack Engineer
    ________________
    Modus Create is based on the model of an open source team. We’re a remote, global team of experts in our field. To find out more about the work we do, head over to our website.

    Check out my GitHub:
    https://github.com/mitchellsimoens

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
  •