pm.sreejith
3 Nov 2011, 9:12 PM
Hi All,
Can you please tell me the ways to access the objects of components which placed inside of an component from a controller?. I am using sencha touch 2.0 with MVC architecture
Please go through the code below and let me know.
Controller
--------------------
Ext.define('Sencha.controller.Main', {
extend: 'Ext.app.Controller',
views: ['Home', 'Products', 'Contact', 'Article','LatestArticles','ContentList', 'ContentCarousel'],
refs: [
{
ref: 'contactForm',
selector: '#contactForm'
},
{
ref: 'homePanel',
selector: 'homepanel'
}
],
stores: [
'Mains', 'Contentlist'
],
init: function() {
this.control({
'button[action=submitContact]': {
tap: 'submitContactForm'
}
});
Ext.Msg.alert("Count->>>", this.getHomePanel().this.getArticlesPage().items.length, function(){});
},
submitContactForm: function() {
var form = this.getContactForm();
form.submit({
url: 'contact.php'
});
}
});
Home View
--------------------
Ext.define('Sencha.view.Home', {
extend: 'Ext.Panel',
xtype: 'homepanel',
config: {
title: 'Home',
iconCls: 'home',
cls: 'home',
items:[
{
xtype: 'container',
items: [{
xtype: 'articlespage',
flex:3
}]
},
{
xtype: 'latestarticles',
flex:1
}
]
}
});
Artcles View
---------------------
Ext.define('Sencha.view.Article', {
extend: 'Ext.Carousel',
xtype: 'articlespage',
id: 'articlespage',
config: {
title: 'Articles',
iconCls: 'star',
height: 400,
items: [
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 1</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Animator.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 2</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Charts.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 3</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Designer.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 4</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Designer.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 5</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Animator.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 6</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Charts.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 7</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Designer.png' border='0'/></div></div>"
}
],
listeners:
{
afterRender: function() {
Ext.Carousel.superclass.afterRender.call(this);
this.scroller.on({
touchend: this.onTouchEnd,
scrollend: this.onScrollEnd,
scope: this
});
}
}
}
});
So in this example, I want to get the object of the view article from the controller. How it is possible?
Please let me know if anybody have any solution...:-?
Advance thanks to all....
Regards,
Sreejith
Can you please tell me the ways to access the objects of components which placed inside of an component from a controller?. I am using sencha touch 2.0 with MVC architecture
Please go through the code below and let me know.
Controller
--------------------
Ext.define('Sencha.controller.Main', {
extend: 'Ext.app.Controller',
views: ['Home', 'Products', 'Contact', 'Article','LatestArticles','ContentList', 'ContentCarousel'],
refs: [
{
ref: 'contactForm',
selector: '#contactForm'
},
{
ref: 'homePanel',
selector: 'homepanel'
}
],
stores: [
'Mains', 'Contentlist'
],
init: function() {
this.control({
'button[action=submitContact]': {
tap: 'submitContactForm'
}
});
Ext.Msg.alert("Count->>>", this.getHomePanel().this.getArticlesPage().items.length, function(){});
},
submitContactForm: function() {
var form = this.getContactForm();
form.submit({
url: 'contact.php'
});
}
});
Home View
--------------------
Ext.define('Sencha.view.Home', {
extend: 'Ext.Panel',
xtype: 'homepanel',
config: {
title: 'Home',
iconCls: 'home',
cls: 'home',
items:[
{
xtype: 'container',
items: [{
xtype: 'articlespage',
flex:3
}]
},
{
xtype: 'latestarticles',
flex:1
}
]
}
});
Artcles View
---------------------
Ext.define('Sencha.view.Article', {
extend: 'Ext.Carousel',
xtype: 'articlespage',
id: 'articlespage',
config: {
title: 'Articles',
iconCls: 'star',
height: 400,
items: [
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 1</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Animator.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 2</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Charts.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 3</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Designer.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 4</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Designer.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 5</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Animator.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 6</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Charts.png' border='0'/></div></div>"
},
{
html:"<div style='float:left;width:100%;'><div style='float:left;width:50%;margin-top:30px;'><h1>Title - 7</h1>Built with HTML5 Canvas, Touch Charts includes gesture-based <a href='#'>Read More >></a></div><div style='float:left;width:50%;'><img src='resources/images/Designer.png' border='0'/></div></div>"
}
],
listeners:
{
afterRender: function() {
Ext.Carousel.superclass.afterRender.call(this);
this.scroller.on({
touchend: this.onTouchEnd,
scrollend: this.onScrollEnd,
scope: this
});
}
}
}
});
So in this example, I want to get the object of the view article from the controller. How it is possible?
Please let me know if anybody have any solution...:-?
Advance thanks to all....
Regards,
Sreejith