Listview itemtap executes the same controller function - sencha-touch

I have 2 ListView's in my application, when a user clicks on an item of each listview item, the page should navigate to a different view.
In my case, when i click on each views it navigates to the same view. It seems like when the user taps on an item of the view it calls the same controller function. Here's my code, can someone help me solve this;
Ext.define('MyApp.controller.MyCOntroller', {
extend: 'Ext.app.Controller',
config: {
refs: {
OneList: 'onel',
TwoList: 'twol'
},
control: {
"list": {
itemtap: 'onOnelTap'
},
"list": {
itemtap: 'twolClicked'
}
}
},
onOnelTap: function(dataview, index, target, record, e, eOpts) {
console.log("hhhhhh "+e.event.target.nodeName);
},
courtRoomListClicked: function(dataview, index, target, record, e, eOpts) {
console.log(" 2 -- >list");
}
});

It seems that you have not declared your refs and controls properly.
Let's say your OneList has an id called one-list, then the refs and controls should be declared like this:
config: {
refs: {
OneList: 'one-list'
},
control: {
"OneList": {
itemtap: 'onOnelTap'
}
}
},
The rest is okay. Hope this helps.

If i understood correctly, your control configuration is not good and you may need to do like this
Ext.define('MyApp.controller.MyCOntroller', {
extend: 'Ext.app.Controller',
config: {
refs: {
// I assume that 'onel' and 'twol' are xtype of respective views
OneList: 'onel',
TwoList: 'twol'
},
control: {
OneList: {
itemtap: 'onOnelTap'
},
TwoList: {
itemtap: 'onTwolTap'
}
}
},
onOnelTap: function(dataview, index, target, record, e, eOpts) {
console.log("onOnel Tap ");
},
onTwolTap: function(dataview, index, target, record, e, eOpts) {
console.log("onTwol Tap");
}
});

Related

How to implement click event for panel in sencha touch in controller

Can anybody tell How to implement clickor tap event for panel in sencha touch in controller
Thanks
Ext.define('FirstApp.controller.details', {
extend: 'Ext.app.Controller',
config: {
stores : ['your store'],
models : ['your model'],
refs: {
myContainer: 'your view'
},
control: {
'your view': {
activate: 'onActivate',// fires when view is activated
itemtap: 'onItemTap',// fires when item is tapped
}
}
},
onActivate: function() {
console.log('Main container is active');
},
onItemTap: function(view, index, target, record, event) {
console.log('Item was tapped on the Data View');
console.log(view, index, target, record, event);
Ext.Msg.alert('', 'The user selected is: ' + record.get('username'));
},
});
Implement tap of Panel like this. It will work.
Ext.define('YourApp.view.text', {
extend: 'Ext.Panel',
xtype: 'text',
initialize: function () {
this.element.on({
tap: function () { alert('tapped!'); }
});
}
});

How to implement listview item tap event in controller in sencha touch

Can anybody tell How to implement listview item tap event in controller in sencha touch
Thanks
Do the following:
If your list is like below:
{
xtype: 'list',
name: 'myList',
store: 'test'
}
Then your controller will go like this:
config: {
refs: {
myList: 'list[name="myList"]'
},
control: {
myList: {
itemtap: 'onItemTap' // fires when listitem is tapped
}
}
},
onItemTap: function(view, index, target, record, event) {
console.log('List Item was tapped of the list view');
........ your code goes here .........
}
Note: These small things you can find in sencha docs.

How to switch a view container using Sencha Touch?

How do I switch views in Sencha Touch? Currently I have a new view being shown, but it looks like it overlays onto the existing one. I think I need to hide the previous or destroy it. I was thinking of maybe using Ext.getCmp("noteslist") but this returns 'undefined' when trying to get the current container. Is this the recommended way of navigating between views or is there a better way?
App
Ext.application({
name: "NotesApp",
controllers: ["NotesController", "TestController"],
views: ["NotesListContainer"],
launch: function () {
var notesListContainer = Ext.create("NotesApp.view.NotesListContainer");
Ext.Viewport.add(notesListContainer);
}
});
Controller:
Ext.define("NotesApp.controller.NotesController", {
extend: "Ext.app.Controller",
views: [
"TestListContainer"
],
config: {
refs: {
newNoteBtn: "#new-note-btn",
saveNoteBtn: "#save-note-btn",
},
control: {
newNoteBtn: {
tap: "onNewNote"
},
saveNoteBtn: {
tap: "onSaveNote"
}
}
},
onNewNote: function () {
console.log("onNewNote");
},
onSaveNote: function () {
console.log("onSaveNote");
Ext.Viewport.add({xtype:'testlist'}).show();
// How do I remove the current one?....
},
launch: function () {
this.callParent();
console.log("launch");
},
init: function () {
this.callParent();
console.log("init");
}
});
View
Ext.define("NotesApp.view.NotesListContainer", {
extend: "Ext.Container",
config: {
items: [{
xtype: "toolbar",
docked: "top",
title: "My Notes",
items: [{
xtype: "spacer"
}, {
xtype: "button",
text: "New",
ui: "action",
id:"new-note-btn"
}, {
xtype: "button",
text: "Save",
ui: "action",
id:"save-note-btn"
}]
}]
}
Using Ext.Viewport.add you only add component to viewport, but not set it as active item. You can use Ext.Viewport.setActiveItem for add component and set it as active item in one call.
Example:
//1
Ext.Viewport.setActiveItem({xtype:'testlist'});
//or 2
//Create and add to viewport
Ext.Viewport.add({xtype:'testlist'});
//set active item by index
Ext.Viewport.setActiveItem(1);
//or 3
var list = Ext.create('NotesApp.view.NotesListContainer', {id : 'noteList'});
Ext.Viewport.add(list);
.....
//In place where you need to show list
Ext.Viewport.setActiveItem(list);
If you want to animate swiching between views then use animateActiveItem(list, {type: 'slide', direction: 'right'}) instead a setActiveItem.
It's how you can work with Ext.Viewport and any container with card layout. In the real application view can be created in one part of app(in the controller, int the app, in the view) and set as active in other part. In this case you need get link to the list by any way and use it in the setActiveItem.
There are two techniques 1 using setActiveItem and the other using navigation view...
Navigation View
Set Active item method:
var view=Ext.Viewport.add({xtype: 'testlist'});
Ext.Viewport.setActiveItem(view);
view.show(); //This is additionally done to fire showAnimation

Tabview of setActiveItem(0) is not displaying content of page in sencha touch2

i have four separete view, adding these four view in single tabview as shown below.
Tab View Code:
Ext.define("SLS.BRND.WEB.view.MainTabbarView", {
extend: 'Ext.tab.Panel',
xtype: 'MainTabbarView',
requires: ['Ext.data.proxy.JsonP', 'Ext.TitleBar', 'Ext.Video', 'SLS.BRND.WEB.view.GallerysView', 'SLS.BRND.WEB.view.FloorView'],
config: {
tabBarPosition: 'bottom',
items: [
{
xclass: "SLS.BRND.WEB.view.GlobalNavigationView",
docked: "top",
scrollable: false
},
{
xclass: 'SLS.BRND.WEB.view.ApartmentView'
},
{
xclass: 'SLS.BRND.WEB.view.SpecificationView'
},
{
xclass: 'SLS.BRND.WEB.view.FloorView'
},
{
xclass: 'SLS.BRND.WEB.view.GallerysView'
}
]
}
});
In controller onbuttontap function i am calling above 'MainTabbarView' page as shown below. i have set setActiveItem(0); to display first tabitem among four i.e (xclass: 'SLS.BRND.WEB.view.ApartmentView'). when i set like this setActiveItem(0) it will dispaly first view page but without data(blank screen).if i set like this setActiveItem(1), it will dispaly second view page with data. then i thought may be problem in first page, so i have changed order of page view in 'MainTabbarView'. again i set setActiveItem(0) then it showing active page but without data. i have keep on changed setActiveItem(0) to 1,2,3 its working fine and also data displaying. but for the setActiveItem(0) data is not displaying. can any help me . how to resolve this issue. thank you
Controller Code :
Ext.define("SLS.BRND.WEB.controller.ApartmentController", {
extend: "Ext.app.Controller",
requires: ['Ext.data.proxy.JsonP'],
config: {
refs: {
projectsPage: "projectspage",
mainTabbarView: "MainTabbarView",
},
control: {
projectsPage: {
BtnApartments: "onAptButtonTap"
}
}
},
onAptButtonTap: function () {
var ApartmentTabbar = this.getMainTabbarView();
ApartmentTabbar.setActiveItem(0);
Ext.Viewport.animateActiveItem(ApartmentTabbar, this.slideLeftTransition);
},
activateNotesList: function () {
Ext.Viewport.animateActiveItem(this.getHomepage(), this.slideRightTransition);
},
slideRightTransition: { type: 'slide', direction: 'right' },
slideDownTransition: { type: 'flip', direction: 'down' },
slideLeftTransition: { type: 'fade', direction: 'left' }
});
Your onAptButtonTap function is not in the right place, you put it in the config as you should put it after the config like so :
...
config: {
refs: {
projectsPage: "projectspage",
mainTabbarView: "MainTabbarView",
},
control: {
projectsPage: {
BtnApartments: "onAptButtonTap"
}
},
...
},
onAptButtonTap: function () {
var ApartmentTabbar = this.getMainTabbarView();
ApartmentTabbar.setActiveItem(0);
Ext.Viewport.animateActiveItem(ApartmentTabbar, this.slideLeftTransition);
},
...

Adding buttons to a dataview row?

I'm trying out the new dataview component and I'm working with this Sencha example:
http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2/
In KittensListItem, I removed the image and now I want to add three
buttons that say: "Email", "Facebook", and "Twitter", and not the
value in the Store. When the user clicks on each button, I'd like to
show each button's respective Store value. How can this be accomplished?
Here's what the screen looks like at the moment:
Example.view.KittensListItem:
Ext.define('Example.view.KittensListItem', {
extend: 'Ext.dataview.component.DataItem',
xtype : 'contactslistitem',
requires: [ 'Ext.Button', 'Ext.slider.Slider' ],
config: {
dataMap: {
getName: { setHtml: 'name' },
getSlider: { setValue: 'cuteness' },
getEmail: { setHtml: 'email' },
getTwitter: { setHtml: 'twitter' },
getFacebook: { setHtml: 'facebook' }
},
name: { flex: 1 },
slider: { flex: 1 },
email: {
text: 'Email',
style: 'font-size: 12px;',
flex: 1
},
facebook: {
text: 'Facebook1',
style: 'font-size: 12px;',
flex: 1
},
twitter: {
text: 'Twitter',
style: 'font-size: 12px;',
flex: 1
},
layout: {
type: 'hbox',
align: 'center'
}
},
applyName: function(config) { return Ext.factory(config, Ext.Component, this.getName()); },
updateName: function(newName, oldName) {
if (newName) { this.add(newName); }
if (oldName) { this.remove(oldName); }
},
applySlider: function(config) { return Ext.factory(config, Ext.slider.Slider, this.getSlider()); },
updateSlider: function(newSlider, oldSlider) {
if (newSlider) { this.add(newSlider); }
if (oldSlider) { this.remove(oldSlider); }
},
applyEmail: function(config) { return Ext.factory(config, Ext.Button, this.getEmail()); },
updateEmail: function(newEmailButton, oldEmailButton) {
if (newEmailButton) { this.add(newEmailButton); }
if (oldEmailButton) { this.remove(oldEmailButton); }
},
applyTwitter: function(config) {return Ext.factory(config, Ext.Button, this.getTwitter()); },
updateTwitter: function(newTwitterButton, oldTwitterButton) {
if (newTwitterButton) { this.add(newTwitterButton); }
if (oldTwitterButton) { this.remove(oldTwitterButton); }
},
applyFacebook: function(config) { return Ext.factory(config, Ext.Button, this.getFacebook()); },
updateFacebook: function(newFacebookButton, oldFacebookButton) {
if (newFacebookButton) { this.add(newFacebookButton); }
if (oldFacebookButton) { this.remove(oldFacebookButton); }
}
});
Model:
Ext.define('Example.model.Kitten', {
extend: 'Ext.data.Model',
config: {
fields: [
"name",
"email",
"twitter",
"facebook",
{ name: "cuteness", type: 'int' }
]
}
});
Store:
Ext.define('Example.store.Kittens', {
extend: 'Ext.data.Store',
requires: ['Example.model.Kitten'],
config: {
model: 'Example.model.Kitten',
data: [
{ name: 'one', email: 'email#addr', twitter: '#twitter', facebook: 'Facebook...', cuteness: 70 },
{ name: 'two', email: 'email#addr', twitter: '#twitter', facebook: 'Facebook...', cuteness: 90 },
{ name: 'three', email: 'email#addr',twitter: '#twitter', facebook: 'Facebook...',cuteness: 40 }
]
}
});
After scouring the Internet I found a solution to the 'tap' event for each button. The trick is to add a tap listener in the update* functions. I'm still not sure how to set the static labels on each button.
Btw, a better answer gets someone else the upvote and check.
updateEmail: function(newEmailButton, oldEmailButton) {
if (newEmailButton) {
newEmailButton.on('tap', this.onEmailButtonTap, this);
this.add(newEmailButton);
}
if (oldEmailButton) {
this.remove(oldEmailButton);
}
},
onEmailButtonTap: function(button, event) {
var record = this.getRecord();
Ext.Msg.alert(record.get('email') + ", " + record.get('facebook') );
}
Hi I'm new to Sencha Touch and having problems too getting started. I came across this post looking for ways to access dataview item components/values from a controller. In my case I'm looking to use a slider and editbox value together and automatically update either value after updates.
Dataview has an itemtap listener which is handy returning the row index and the record as mentioned in this post. I still found it was a problem to pin down the component that was tapped so ended up just filtering the component by event object name.
Controller:
control: {
'contactslistitem': {
itemtouchend: 'tapItem',
}
}
tapItem: function(dataview, index, target, record, e, eOpts) {
if('facebookbutton'==e.target.name)
alert('Tapped facebook button on row '+index);
}
The dataview config for the facebook button element includes the name attribute:
facebook: {
name: 'facebookbutton'
text: 'Facebook1',
style: 'font-size: 12px;',
flex: 1
},
I still feel there must be a better way with ST2 to process dataview rows components together without having to look up the index/component each time.