SlideShare uma empresa Scribd logo
1 de 4
Writing your first Sencha Touch application – Part2

Till now we have seen how to create a viewport panel and dock a toolbar on top of the Panel. Lets build the rest of
the application. Ok, now we need a List and some contact information that the list will hold.
To create a list we will use the standard Ext.List component class and set properties in its configuration object. This
is how to create a list

var contactList = new Ext.List({

                                         store: store,

                                         itemTpl: itemTemplate,

                                         height:"100%"

                                  });


A list needs data to display as items and to do so we have the store property. This property defines
a Ext.data.Storeobject that holds the data and the schema that defines the structure of the data. I am using the term
schema for the data modelling because it seems to make things familiar to me.
Schema – Models and Stores
I have briefly talked about Stores above. Ext.data.Store objects are actually like your client side database. It will hold
data that our list will display. For eg. it will hold the first names and last names of the people. Now stores also define
model objects which tells the store about the structure of the data to hold. Model is the schema that I was talking
about. Every row in a store will be an item in the list. And every row in a store is a Model instance.
Both Storeand Model are part of Ext.data package. This is how to do so,

Ext.regModel('Contact', {

            fields: ['firstName', 'lastName']

});




var data = [

            {firstName: 'Pearlie', lastName: 'White'},

            {firstName: 'John', lastName: 'Suttle'},

            {firstName: 'Javier', lastName: 'Henderson'},

            {firstName: 'Young', lastName: 'Alverd'},

            {firstName: 'Pearlie', lastName: 'white'},
{firstName: 'Billy', lastName: 'Artega'},

            {firstName: 'Dona', lastName: 'Bigglker'},

            {firstName: 'Alfred', lastName: 'Blackburn'},

            {firstName: 'Trenton', lastName: 'Bollinger'},

            {firstName: 'Tom', lastName: 'Foose'}

      ];




var store = new Ext.data.Store({

            model: 'Contact',

            data: data

});


As you can see we have registered a Model with Ext.regModel() and given it a name Contact, fields specify the
name of the fields which in this case are firstName and lastName. Then I have defined a data array which holds the
data for our list. It is an array of Model objects and note that same field names have been used from our Model
registered earlier. The model and the data are then specified in the Store as you can see. I have used inline or hard-
coded data for my Store. There are other options available as well. You can load data in your store from remote
servers. You can make Ajax calls and receive XML, JSONP data and load it in your store via a Proxy. Well lets keep
this aside for now. I will come up with something that will showcase dynamic data loading using proxies.
Templates
Next thing to do is to define how your list items look like and what fields defined in the Model will actually be displayed
in each item. To do so we have to use the Ext.XTemplate class. By using it we can define a template and put custom
styles(CSS) and HTML elements that will wrap the data. This is how to do so,

var itemTemplate = new Ext.XTemplate(

                                              '<tpl for=".">',

                                                          '{firstName} {lastName}',

                                              '</tpl>'

                                  );


In our case we have defined a template that will display the firstName and lastName of the contacts. Note that I have
not used any div or custom css to style the items. The <tpl for=” . “> is for looping through the items of the data
array, for = ” . ” means that the looping will start from the root. The data array that I I have mentioned is a linear array
so there are no children, the thing that would have been in a typical XML document. To add custom styles you could
have written something like this,

var itemTemplate = new Ext.XTemplate(

                                              '<tpl for=".">',

                                                     '<div style="color:#fff;background-
color:#ff0000;">',

                                                           '{firstName} {lastName}',

                                                     '</div>',

                                              '</tpl>'

                                    );


Integrating
Now that we have our Model, Data, Store and Template ready, lets bind these to our list. This is how to do so,

 var contactList = new Ext.List({

                                           store: store,

                                           itemTpl: itemTemplate,

                                           height:"100%"

                                    });


Its simple isn’t it. Just name the store and item template objects in the properties. A height of 100% means that the
list will occupy the entire height of the application screen. Percentages are allowed.
Our list is ready now. So need to add this to our viewport panel. Remember a list is only a component. It needs to be
added to a container for display. This is how you can do it,

new Ext.Panel({

                                          fullscreen:true,

                                          layout:'fit',

                                          dockedItems:[{xtype:'toolbar', title:'Contact List'}],

                                          dock:'top',

                                          scroll:'vertical',
items:[contactList]

                                   });


Note the items property. It is an array of all the items that the panel will hold. Add your contact list object to it. That’s
it, our first Sencha Touch application is ready. Run your code and you should be able to see a list of people’s contact
information as shown below,




                                                      Sencha Touch list

Here is the link to the demo http://jbk404.site50.net/sencha/gettingstarted/. Try opening it in your iPhone. If you do not
have one try it out here http://www.iphonetester.com/.
Adding interactivity
Next thing is to add interactivity to our list. Lets say, when a user taps on one of the contact he should be able to see
more information about the person in a pop up. Lets keep this for the next part. Part3 is ready. Read it here.
Link to part 1 : http://jbkflex.wordpress.com/2011/07/30/writing-your-first-sencha-touch-application-part1/

Mais conteúdo relacionado

Último

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 

Último (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 

Destaque

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destaque (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Writing your first sencha touch application part2

  • 1. Writing your first Sencha Touch application – Part2 Till now we have seen how to create a viewport panel and dock a toolbar on top of the Panel. Lets build the rest of the application. Ok, now we need a List and some contact information that the list will hold. To create a list we will use the standard Ext.List component class and set properties in its configuration object. This is how to create a list var contactList = new Ext.List({ store: store, itemTpl: itemTemplate, height:"100%" }); A list needs data to display as items and to do so we have the store property. This property defines a Ext.data.Storeobject that holds the data and the schema that defines the structure of the data. I am using the term schema for the data modelling because it seems to make things familiar to me. Schema – Models and Stores I have briefly talked about Stores above. Ext.data.Store objects are actually like your client side database. It will hold data that our list will display. For eg. it will hold the first names and last names of the people. Now stores also define model objects which tells the store about the structure of the data to hold. Model is the schema that I was talking about. Every row in a store will be an item in the list. And every row in a store is a Model instance. Both Storeand Model are part of Ext.data package. This is how to do so, Ext.regModel('Contact', { fields: ['firstName', 'lastName'] }); var data = [ {firstName: 'Pearlie', lastName: 'White'}, {firstName: 'John', lastName: 'Suttle'}, {firstName: 'Javier', lastName: 'Henderson'}, {firstName: 'Young', lastName: 'Alverd'}, {firstName: 'Pearlie', lastName: 'white'},
  • 2. {firstName: 'Billy', lastName: 'Artega'}, {firstName: 'Dona', lastName: 'Bigglker'}, {firstName: 'Alfred', lastName: 'Blackburn'}, {firstName: 'Trenton', lastName: 'Bollinger'}, {firstName: 'Tom', lastName: 'Foose'} ]; var store = new Ext.data.Store({ model: 'Contact', data: data }); As you can see we have registered a Model with Ext.regModel() and given it a name Contact, fields specify the name of the fields which in this case are firstName and lastName. Then I have defined a data array which holds the data for our list. It is an array of Model objects and note that same field names have been used from our Model registered earlier. The model and the data are then specified in the Store as you can see. I have used inline or hard- coded data for my Store. There are other options available as well. You can load data in your store from remote servers. You can make Ajax calls and receive XML, JSONP data and load it in your store via a Proxy. Well lets keep this aside for now. I will come up with something that will showcase dynamic data loading using proxies. Templates Next thing to do is to define how your list items look like and what fields defined in the Model will actually be displayed in each item. To do so we have to use the Ext.XTemplate class. By using it we can define a template and put custom styles(CSS) and HTML elements that will wrap the data. This is how to do so, var itemTemplate = new Ext.XTemplate( '<tpl for=".">', '{firstName} {lastName}', '</tpl>' ); In our case we have defined a template that will display the firstName and lastName of the contacts. Note that I have not used any div or custom css to style the items. The <tpl for=” . “> is for looping through the items of the data
  • 3. array, for = ” . ” means that the looping will start from the root. The data array that I I have mentioned is a linear array so there are no children, the thing that would have been in a typical XML document. To add custom styles you could have written something like this, var itemTemplate = new Ext.XTemplate( '<tpl for=".">', '<div style="color:#fff;background- color:#ff0000;">', '{firstName} {lastName}', '</div>', '</tpl>' ); Integrating Now that we have our Model, Data, Store and Template ready, lets bind these to our list. This is how to do so, var contactList = new Ext.List({ store: store, itemTpl: itemTemplate, height:"100%" }); Its simple isn’t it. Just name the store and item template objects in the properties. A height of 100% means that the list will occupy the entire height of the application screen. Percentages are allowed. Our list is ready now. So need to add this to our viewport panel. Remember a list is only a component. It needs to be added to a container for display. This is how you can do it, new Ext.Panel({ fullscreen:true, layout:'fit', dockedItems:[{xtype:'toolbar', title:'Contact List'}], dock:'top', scroll:'vertical',
  • 4. items:[contactList] }); Note the items property. It is an array of all the items that the panel will hold. Add your contact list object to it. That’s it, our first Sencha Touch application is ready. Run your code and you should be able to see a list of people’s contact information as shown below, Sencha Touch list Here is the link to the demo http://jbk404.site50.net/sencha/gettingstarted/. Try opening it in your iPhone. If you do not have one try it out here http://www.iphonetester.com/. Adding interactivity Next thing is to add interactivity to our list. Lets say, when a user taps on one of the contact he should be able to see more information about the person in a pop up. Lets keep this for the next part. Part3 is ready. Read it here. Link to part 1 : http://jbkflex.wordpress.com/2011/07/30/writing-your-first-sencha-touch-application-part1/