问题
I am having two views
- Search.js with items fieldsets and a button
- ContactList.js with list of contacts
I have a controller Main.js
I want to implement a functionality in Sencha Touch 2 that, when button on Search.js is clicked, contact list from ContactList.js should be displayed. How do I do this?
回答1:
First of all, add an action or an id to your Search button in the view
{
title: "My Button",
xtype: 'button',
action: 'call-contact-list',
}
Then in your controller, you need to implement what is going to happen when the button is clicked. Take the following code as an illustration. The code needs to be inside the control config:
control: {
'button[action=call-contact-list]': {
tap: 'myFunction'
}
}
myFunction: function() {
//Code to run when the button has been clicked.
//In this case, loading ContactList.js which should be something like this:
Ext.Viewport.add({
xtype: 'contactlist' //the xtype for the ContactList.js
});
},
来源:https://stackoverflow.com/questions/11185667/how-to-open-a-new-view-on-button-click-in-sencha-touch-2