Here I am trying to add a simple toolbar with an embedded button and following these is a list of some items. I want this list to get sorted once i click on sort button.
The following is the view code :
Ext.define('UtilApp.view.Main', {
extend: 'Ext.Container',
xtype: 'main',
initialize: function(){
this.callParent(arguments);
var Arr = new Array("Banana", "Apple", "Orange", "Peach", "Guava", "Pine", "Dates");
var sortButton = {
xtype: 'button',
text: 'sort',
handler: this.sorter(Arr)
};
var toolbar = {
xtype: 'toolbar',
title: Ext.Date.DAY,
docked: 'top',
items : [sortButton]
};
var list = Ext.create('Ext.List', {
fullscreen: true,
itemTpl: '{title}',
data: [
{title: Arr[0]},
{title: Arr[1]},
{title: Arr[2]},
{title: Arr[3]},
{title: Arr[4]},
{title: Arr[5]},
{title: Arr[6]}
]
});
console.log("List Created!");
this.add([toolbar, list]);
},
sorter: function(Arr, toolbar, list){
console.log("Starting sort");
var sortedArray = Ext.Array.sort(Arr);
console.log(sortedArray);
console.log("Sorted");
this.add([this.toolbar, this.list]);
console.log("added");
}
});
extend: 'Ext.Container',
xtype: 'main',
initialize: function(){
this.callParent(arguments);
var Arr = new Array("Banana", "Apple", "Orange", "Peach", "Guava", "Pine", "Dates");
var sortButton = {
xtype: 'button',
text: 'sort',
handler: this.sorter(Arr)
};
var toolbar = {
xtype: 'toolbar',
title: Ext.Date.DAY,
docked: 'top',
items : [sortButton]
};
var list = Ext.create('Ext.List', {
fullscreen: true,
itemTpl: '{title}',
data: [
{title: Arr[0]},
{title: Arr[1]},
{title: Arr[2]},
{title: Arr[3]},
{title: Arr[4]},
{title: Arr[5]},
{title: Arr[6]}
]
});
console.log("List Created!");
this.add([toolbar, list]);
},
sorter: function(Arr, toolbar, list){
console.log("Starting sort");
var sortedArray = Ext.Array.sort(Arr);
console.log(sortedArray);
console.log("Sorted");
this.add([this.toolbar, this.list]);
console.log("added");
}
});
I am getting an error as follows :
Uncaught Error: [ERROR][Ext.Container#add] Invalid item given: undefined, must be either the config object to factory a new item, or an existing component instance
The list is not appearing in the screen if i remove this handler. I could not figure out what the error means as I am new to sencha touch and also Ext.js . Please help.