Skip to content

Instantly share code, notes, and snippets.

@mitchellsimoens
Created September 17, 2012 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellsimoens/3739543 to your computer and use it in GitHub Desktop.
Save mitchellsimoens/3739543 to your computer and use it in GitHub Desktop.
DataView vs List with Compoennts
/**
* This must use Sencha Touch 2.1.0 beta 3
* This shows how similar using components is in DataView and List
*/
Ext.define('MyDataItem', {
extend : 'Ext.dataview.component.DataItem',
xtype : 'mydataitem',
//<debug>
requires : [
'Ext.Button',
'Ext.layout.HBox'
],
//</debug>
config : {
dataMap : {
getTest : {
setHtml : 'test'
}
},
test : {
flex : 1
},
btn : {
text : 'Hi'
},
layout : {
type : 'hbox',
pack : 'center'
}
},
applyTest : function (config) {
return Ext.factory(config, Ext.Component, this.getTest());
},
updateTest : function (test) {
if (test) {
this.add(test);
}
},
applyBtn : function (config) {
return Ext.factory(config, Ext.Button, this.getBtn());
},
updateBtn : function (btn) {
if (btn) {
this.add(btn);
}
}
});
Ext.define('MyListItem', {
extend : 'Ext.dataview.component.ListItem',
xtype : 'mylistitem',
//<debug>
requires : [
'Ext.Button',
'Ext.layout.HBox'
],
//</debug>
config : {
dataMap : {
getTest : {
setHtml : 'test'
}
},
test : {
flex : 1
},
btn : {
text : 'Hi'
},
layout : {
type : 'hbox',
pack : 'center'
}
},
applyTest : function (config) {
return Ext.factory(config, Ext.Component, this.getTest());
},
updateTest : function (test) {
if (test) {
this.add(test);
}
},
applyBtn : function (config) {
return Ext.factory(config, Ext.Button, this.getBtn());
},
updateBtn : function (btn) {
if (btn) {
this.add(btn);
}
}
});
Ext.application({
name : 'Test',
//<debug>
requires : [
'Ext.dataview.List',
'Ext.data.Store',
'Ext.layout.HBox'
],
//</debug>
viewport : {
layout : {
type : 'hbox',
align : 'stretch'
},
defaults : {
flex : 1
}
},
launch : function () {
Ext.Viewport.add([
{
xtype : 'dataview',
useComponents : true,
defaultType : 'mydataitem',
store : {
fields : ['test'],
data : [
{ test : 'One' },
{ test : 'Two' },
{ test : 'Three' }
]
}
},
{
xtype : 'list',
useComponents : true,
defaultType : 'mylistitem',
store : {
fields : ['test'],
data : [
{ test : 'One' },
{ test : 'Two' },
{ test : 'Three' }
]
}
}
]);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment