Todo List App using Sencha – Part 2

In the 1st Part we generate, build and run sencha touch project using terminal/command prompt. In this part we’ll start create controller and model using terminal/command prompt.

To create controller with Sencha CMD it is enough to execute the following command:

sencha generate controller Task
Sencha Controller

Sencha Controller

It generates for us controllers/Main.js file. It is generic and has minimum content:

Ext.define('RevivalxSenchaTodolist.controller.Task', {
    extend: 'Ext.app.Controller',
    
    config: {
        refs: {
            
        },
        control: {
            
        }
    },
    
    //called when the Application is launched, remove if not needed
    launch: function(app) {
        
    }
});

To instantiate controller automatically we have to add it into controllers configuration section (app.js) in application next way:

controllers: [ 'Task' ]

Then we generate a Task model using this command:

com.revivalx.sencha.todolist MNurdin$ sencha generate model Task tasId:int,name:string,description:string,dateCreated:string,dateUpdated:string
Sencha Model

Sencha Model

And in model folder, we should see file Task.js:

Ext.define('RevivalxSenchaTodolist.model.Task', {
    extend: 'Ext.data.Model',
    
    config: {
        fields: [
            { name: 'tasId', type: 'int' },
            { name: 'name', type: 'string' },
            { name: 'description', type: 'string' },
            { name: 'dateCreated', type: 'string' },
            { name: 'dateUpdated', type: 'string' }

        ]
    }
});

To work with this model in our application we should add RevivalxSenchaTodolist.model.Task to requires section, usually we do it in controllers or stores.

Continue..

Leave a Reply

Your email address will not be published. Required fields are marked *