Need to create a list in sencha touch 2 with items like
label1
label2
button1 button2 button3
label1
label2
button1 button2 button3
on clicking the button a poppup should come pointing it.
I know I need to use Dataview for creating the list. But I have no idea of creating such a layout using dataview. any help would greatly appreciated.
Here is the code required to create your layout.
Ext.Loader.setConfig({
enabled: true
});
Ext.application({
launch: function () {
Ext.define('MyListItem', {
extend: 'Ext.dataview.component.DataItem',
requires: ['Ext.Button'],
xtype: 'mylistitem',
config: {
labelPanel:{
itemId:'labelpanel',
layout:'hbox',
defaults:{
//flex:1,
xtype:'label'
}
},
fnameLabel: true,
lnameLabel: {
style:'margin-left:5px'
},
horizontalPanel: {
layout: 'hbox',
defaults:{
xtype:'button',
flex:1
},
items: [{
text: 'First Name',
btnId:1
}, {
text: 'Last Name',
btnId:2
}, {
text: 'Age',
btnId:3
}]
},
dataMap: {
getFnameLabel: {
setHtml: 'fname'
},
getLnameLabel: {
setHtml: 'lname'
}
},
layout: 'vbox'
},
applyFnameLabel: function (config) {
return Ext.factory(config, Ext.Label, this.getFnameLabel());
},
updateFnameLabel: function (newFnameLabel, oldFnameLabel) {
if (oldFnameLabel) {
this.down('panel[itemId="labelpanel"]').remove(oldFnameLabel);
}
if (newFnameLabel) {
this.down('panel[itemId="labelpanel"]').add(newFnameLabel);
}
},
applyLnameLabel: function (config) {
return Ext.factory(config, Ext.Label, this.getLnameLabel());
},
updateLnameLabel: function (newLnameLabel, oldLnameLabel) {
if (oldLnameLabel) {
this.down('panel[itemId="labelpanel"]').remove(oldLnameLabel);
}
if (newLnameLabel) {
this.down('panel[itemId="labelpanel"]').add(newLnameLabel);
}
},
applyLabelPanel: function (config) {
return Ext.factory(config, Ext.Panel, this.getLabelPanel());
},
updateLabelPanel: function (newLabelPanel, oldLabelPanel) {
if (oldLabelPanel) {
this.remove(oldLabelPanel);
}
if (newLabelPanel) {
this.add(newLabelPanel);
}
},
applyHorizontalPanel: function (config) {
return Ext.factory(config, Ext.Panel, this.getHorizontalPanel());
},
updateHorizontalPanel: function (newHorizontalPanel, oldHorizontalPanel) {
if (oldHorizontalPanel) {
this.remove(oldHorizontalPanel);
}
if (newHorizontalPanel) {
//console.info(newHorizontalPanel.down('button[btnId=1]'));
newHorizontalPanel.down('button[btnId=1]').on('tap', this.onButtonTap, this);
newHorizontalPanel.down('button[btnId=2]').on('tap', this.onButtonTap, this);
newHorizontalPanel.down('button[btnId=3]').on('tap', this.onButtonTap, this);
this.add(newHorizontalPanel);
}
},
onButtonTap: function (button, e) {
var record = this.getRecord();
var id = button.config.btnId;
switch(id){
case 1: var value = record.get('fname');break;
case 2: var value = record.get('lname');break;
case 3: var value = record.get('age').toString();break;
}
Ext.Msg.alert(value,"The value is: " +value);
}
});
Ext.create('Ext.DataView', {
fullscreen: true,
store: {
fields: ['fname','lname','age'],
data: [{
fname: 'Jamie',
lname: 'Avins',
age: 100
}, {
fname: 'Rob',
lname: 'Dougan',
age: 21
}, {
fname: 'Tommy',
lname: 'Maintz',
age: 24
}, {
fname: 'Jacky',
lname: 'Nguyen',
age: 24
}, {
fname: 'Ed',
lname: 'Spencer',
age: 26
}]
},
useComponents: true,
defaultType: 'mylistitem'
});
}
});
This fiddle should give you an idea. Read this link from the sencha blog. It explains the code.
Related
I want to show some data from Rally using snapshot sotre passed to teh chart like this:
storeConfig: {
find: {
_ItemHierarchy: 15312401235, //PI Object ID
//Release: 9045474054,
_TypeHierarchy: 'HierarchicalRequirement', //Burn on stories
Children: null, //Only include leaf stories,
_ValidTo: { $gte: me._startDateField.value },
_ValidFrom: { $lte: me._endDateField.value }
},
fetch: ['ScheduleState', 'PlanEstimate'],
hydrate: ['ScheduleState'],
sort: {
'_ValidFrom': 1
}
}
The idea is that I want the chart to show only yhe period between Start Date and End Date specified in me._startDateField.value and me._endDateField.value. What is the way of achieving this? Because now the chart displays the data starting from January and not from Start Date.
This example restricts the end date to a selection in the second rallydatepicker instead of defaulting to today's date. See Readme here.
Ext.define('CustomApp', {
extend: 'Rally.app.App',
componentCls: 'app',
launch: function() {
var that = this;
var minDate = new Date(new Date() - 86400000*90); //milliseconds in day = 86400000
var datePicker = Ext.create('Ext.panel.Panel', {
title: 'Choose start and end dates:',
bodyPadding: 10,
renderTo: Ext.getBody(),
layout: 'hbox',
items: [{
xtype: 'rallydatepicker',
itemId: 'from',
minDate: minDate,
handler: function(picker, date) {
that.onStartDateSelected(date);
}
},
{
xtype: 'rallydatepicker',
itemId: 'to',
minDate: minDate,
handler: function(picker, date) {
that.onEndDateSelected(date);
}
}]
});
this.add(datePicker);
var panel = Ext.create('Ext.panel.Panel', {
id:'infoPanel',
componentCls: 'panel'
});
this.add(panel);
},
onStartDateSelected:function(date){
console.log(date);
this._startDate = date;
},
onEndDateSelected:function(date){
this._endDate = date;
console.log(date);
Ext.getCmp('infoPanel').update('showing data between ' + this._startDate + ' and ' + this._endDate);
this.defineCalculator();
this.makeChart();
},
defineCalculator: function(){
var that = this;
Ext.define("MyDefectCalculator", {
extend: "Rally.data.lookback.calculator.TimeSeriesCalculator",
getMetrics: function () {
var metrics = [
{
field: "State",
as: "Open",
display: "column",
f: "filteredCount",
filterField: "State",
filterValues: ["Submitted","Open"]
},
{
field: "State",
as: "Closed",
display: "column",
f: "filteredCount",
filterField: "State",
filterValues: ["Fixed","Closed"]
}
];
return metrics;
}
});
},
makeChart: function(){
if (this.down('#myChart')) {
this.remove('myChart');
}
var timePeriod = new Date(this._endDate - this._startDate);
var project = this.getContext().getProject().ObjectID;
var storeConfig = this.createStoreConfig(project, timePeriod);
this.chartConfig.calculatorConfig.startDate = Rally.util.DateTime.format(new Date(this._startDate), 'Y-m-d');
this.chartConfig.calculatorConfig.endDate = Rally.util.DateTime.format(new Date(this._endDate), 'Y-m-d');
this.chartConfig.storeConfig = storeConfig;
this.add(this.chartConfig);
},
createStoreConfig : function(project, interval ) {
return {
listeners : {
load : function(store,data) {
console.log("data",data.length);
}
},
filters: [
{
property: '_ProjectHierarchy',
operator : 'in',
value : [project]
},
{
property: '_TypeHierarchy',
operator: 'in',
value: ['Defect']
},
{
property: '_ValidFrom',
operator: '>=',
value: interval
}
],
autoLoad : true,
limit: Infinity,
fetch: ['State'],
hydrate: ['State']
};
},
chartConfig: {
xtype: 'rallychart',
itemId : 'myChart',
chartColors: ['Red', 'Green'],
storeConfig: { },
calculatorType: 'MyDefectCalculator',
calculatorConfig: {
},
chartConfig: {
plotOptions: {
column: { stacking: 'normal'}
},
chart: { },
title: { text: 'Open/Closed Defects'},
xAxis: {
tickInterval: 1,
labels: {
formatter: function() {
var d = new Date(this.value);
return ""+(d.getMonth()+1)+"/"+d.getDate();
}
},
title: {
text: 'Date'
}
},
yAxis: [
{
title: {
text: 'Count'
}
}
]
}
}
});
My button click event subscribed in the controller is getting fired. Here is the code.
WebAppMasterController.js
Ext.define('P.e.w.controller.WebAppMasterController', {
extend: 'P.e.w.controller.IController',
views: [
'WebAppMasterView'
],
refs: [
{
ref: 'webAppView',
selector: 'WebAppMasterView'
}
],
init: function () {
this.control({
'WebAppMasterView': {
afterrender: this.viewafterrender
}
}, {
'button[action=save]': {
click: function () {
alert('dslksd');
}
}
}
},
viewafterrender: function (panel) {
alert();
}
});
IController extends "Ext.app.Controller".
In the above code, the "afterrender" event is getting triggered, but the button click event is not getting triggered.
The view: WebAppMasterView.js
Ext.define('P.e.w.view.WebAppMasterView', {
extend: 'P.w.l.Header',
alias: 'widget.WebAppMasterView',
constructor: function (config) {
var me = this;
me.centerregion = me.createCenterRegion(config);
Ext.applyIf(config, {
favoriteBar: true,
items: [me.centerregion],
menuWidth: 0
});
this.callParent([config]);
},
createBody: function () {
var me = this;
if (!me.controlPanel) {
me.controlPanel = Ext.create('Ext.Panel', {
layout: 'fit'
});
}
return me.controlPanel;
},
createCenterRegion: function (config) {
var me = this,
centerPanel = Ext.create('Ext.Panel', {
region: 'center',
layout: 'fit',
tbar: {
xtype: 'WorkRequestMenuBar',
id: 'workrequestmenubar'
},
defaults: {
border: false
},
items: [me.createBody()]
});
return centerPanel;
}
});
WorkRequestMenuBar.js
Ext.define('P.e.w.view.WorkRequestMenuBar', {
extend: 'Ext.Toolbar', alias: 'widget.WorkRequestMenuBar',
constructor: function (config) {
config = config || {};
Ext.apply(config, {
defaults: {
scale: 'large',
cls: 'x-btn-text-icon',
iconAlign: 'top'
},
items: [
{
text: 'NEW_WORK_REQUEST',
iconCls: 'menubar-createWorkRequest',
action: 'save'
},
{
text: 'OVERVIEW',
iconCls: 'menubar-overview'
}, '->', {
iconCls: 'icon-biggerHelp',
width: 80,
text: 'HELP'
}
]
});
this.callParent([config]);
}
});
You have several issues.
1st. there is a syntax error in your controller
this.control({
'WebAppMasterView': {
afterrender: this.viewafterrender
}
},
{
'button[action=save]': {
click: function () {
alert('dslksd');
}
}
}
//missing --> );
},
2nd. The toolbar config method should be initComponent method instead.
I'm just learning sencha touch 2, MVC. I would to make a simple form that get a value, pass to a PHP file (for an API call to a web-service), move to a Nested List and show results.
But, my app doesn't show nothing after submit... Value is captured correctly (I see it in console log).
Please someone could me help?
Consider for testing that for now I don't pass value, and my API call calls directly with a hard-coded value. In future I'll work to pass form value...
Thank you in advance!
This is "app.js"
Ext.application({
name: 'Appre',
icon: 'resources/icons/icon.png',
phoneStartupScreen: 'resources/images/phone_startup.png',
//tabletStartupScreen: 'tablet_startup.png',
glossOnIcon: false,
//profiles: ['Phone', 'Tablet'],
views : ['Viewport','SearchCap','ElencoRistoranti'],
models: ['ElencoRistoranti'],
stores: ['RistorantiCap'],
controllers: ['SearchCap'],
viewport: {
layout: {
type: 'card',
animation: {
type: 'slide',
direction: 'left',
duration: 300
}
}
},
launch: function() {
Ext.create('Appre.view.Viewport')
} // launch: function() {
}) // Ext.application
This is form "search cap"
Ext.define('Appre.view.SearchCap', {
extend: 'Ext.form.Panel',
xtype: 'appre-searchCap',
config: {
items: [{
xtype: 'fieldset',
layout: 'vbox',
items: [{
xtype: 'textfield',
name: 'cap',
placeHolder: 'Cap'
},
{
xtype: 'button',
text: 'Cerca',
action :'searchCap',
id:'btnSubmitLogin'
}] // items
}] // items
}, // config
initialize: function() {
this.callParent(arguments);
console.log('loginform:initialize');
}
});
This is controller
Ext.define('Appre.controller.SearchCap', {
extend : "Ext.app.Controller",
config : {
refs : {
btnSubmitLogin: 'button[action=searchCap]',
form : 'appre-searchCap'
},
control : {
btnSubmitLogin : {
tap : "onSubmitLogin"
}
}
},
onSubmitLogin : function() {
console.log("onSubmitLogin");
var values = this.getForm().getValues();
console.log(values);
var $this=this;
Ext.Ajax.request({
url: 'cerca-ristoranti-cap.php',
method: 'POST',
params: {
values: Ext.encode({form_fields: values})
},
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
//Ext.Msg.alert('Contact Complete!', obj.responseText);
$this.resetForm();
Ext.Viewport.add(Ext.create('Appre.view.ElencoRistoranti'));
Ext.Viewport.setActiveItem(Ext.create('Appre.view.ElencoRistoranti'));
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});
},
resetForm: function() {
this.getForm().reset();
},
launch : function() {
this.callParent();
console.log("LoginForm launch");
},
init : function() {
this.callParent();
console.log("LoginForm init");
}
});
And this is Nested List
Ext.define('Appre.view.ElencoRistoranti', {
extend: 'Ext.Panel',
xtype: 'appre-elencoristoranti',
config: {
xtype: 'nestedlist',
title: 'Cap',
displayField: 'name',
store: {
type: 'tree',
fields: [
'id_restaurant', 'name',
{name: 'leaf', defaultValue: true}
],
root: {
leaf: false
},
proxy: {
type: 'ajax',
url: 'cerca-ristoranti-cap.php',
reader: {
type: 'json',
rootProperty: 'restaurants'
} //reader
} // proxy
},
detailCard: {
xtype: 'panel',
scrollable: true,
styleHtmlContent: true
},
listeners: {
itemtap: function(nestedList, list, index, element, post) {
this.getDetailCard().setHtml(post.get('name'));
}
}
} // config
});
cerca-ristoranti-cap.php it's a simple function that returns an array like this:
{
"restaurants":[{
"id_restaurant":"40",
"name":"La Saliera",
"zip":"00128",
"lat":"41.7900229",
"lgt":"12.4513128"
}, {
"id_restaurant":"64",
"name":"Osteria del Borgo",
"zip":"00128",
"lat":"41.7887363",
"lgt":"12.5149867"
}]
}
Hi #sineverba sorry for response a little late, but here something this how you want show,
Viewport.js
Ext.define('myapp.view.Viewport' , {
extend : 'Ext.viewport.Default',
xtype : "viewport",
config: {
fullscreen: true,
styleHtmlContent: true,
style: 'background:#ffffff;',
layout : 'card',
autoDestroy : false,
cardSwitchAnimation : 'slide',
items: [
{
xtype: 'appre-searchCap'
},
],
}
})
app.js
Ext.Loader.setConfig({
enabled: true
})
Ext.application({
name: 'myapp',
requires: [
'myapp.view.SearchCap',
'myapp.view.ElencoRistoranti',
'myapp.view.SearchElenco',
],
controllers: ['SearchCap'],
models: ['myapp.model.SearchCapModel'],
launch: function() {
Ext.create('myapp.view.Viewport')
}
});
SearchCapModel.js
Ext.define('myapp.model.SearchCapModel', {
extend: 'Ext.data.Model',
config: {
idProperty: 'id_restaurant',
fields: [
{ name: 'id_restaurant', type: 'string' },
{ name: 'name', type: 'string'},
{ name: 'zip', type: 'string' },
{ name: 'lat', type: 'string'},
{ name: 'lgt', type: 'string'}
],
}
})
SearchCapStore.js
Ext.define('myapp.store.SearchCapStore', {
extend: 'Ext.data.Store',
config: {
model: 'myapp.model.SearchCapModel',
autoLoad: true,
proxy: {
type: 'ajax',
url : 'cerca-ristoranti-cap.json',
reader: {
type: 'json',
rootProperty: 'restaurants'
} //reader
},
}
});
SearchCap.js
Ext.define('myapp.controller.SearchCap', {
extend : "Ext.app.Controller",
views: ['SearchElenco'],
config : {
refs : {
elencoListContainer: 'elencolistcontainer',
btnSubmitLogin: 'button[action=searchCap]',
form : 'appre-searchCap',
},
control : {
btnSubmitLogin : {
tap : "onSubmitLogin"
}
}
},
onSubmitLogin : function() {
console.log("onSubmitLogin");
var values = this.getForm().getValues();
console.log(values);
Ext.Ajax.request({
url: 'cerca-ristoranti-cap.json',
method: 'POST',
params: {
values: Ext.encode({form_fields: values})
},
success: function(response, opts) {
var obj = response.responseText;
Ext.Msg.alert('Contact Complete!', obj);
Ext.Viewport.add(Ext.create('myapp.view.SearchElenco'));
Ext.Viewport.setActiveItem(1);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});
},
resetForm: function() {
this.getForm().reset();
},
launch : function() {
this.callParent();
console.log("LoginForm launch");
},
init : function() {
this.callParent();
console.log("LoginForm init");
}
});
SearchElenco.js
Ext.define('myapp.view.SearchElenco', {
extend: 'Ext.Container',
xtype: 'elencolistcontainer',
requires: ['myapp.store.SearchCapStore'],
initialize: function() {
this.callParent(arguments);
var s = Ext.create('myapp.store.SearchCapStore')
var notesList = {
xtype: 'appre-elencoristoranti',
store: Ext.getStore(s).setAutoLoad(true),
listeners: {
disclose: {
fn: this.onNotesListDisclose,
scope: this
}
}
};
this.add([notesList])
},
onNotesListDisclose: function(list, record, target, index, event, options) {
console.log('editNoteCommand');
this.fireEvent('editNoteCommand', this, record);
},
config: {
layout: {
type: 'fit'
}
}
});
ElencoRistoranti.js
Ext.define('myapp.view.ElencoRistoranti', {
extend: 'Ext.dataview.List',
xtype: 'appre-elencoristoranti',
id: 'appreElenco',
config: {
emptyText: '<pre><div class="notes-list-empty-text">No list found.</div></pre>',
onItemDisclosure: false,
itemTpl: '<pre><div class="list-item-title">{id_restaurant}</div><div class="list-item-narrative">{name}</div></pre>',
}
});
SearchCap.js - View
Ext.define('myapp.view.SearchCap', {
extend: 'Ext.form.Panel',
xtype: 'appre-searchCap',
id: 'appreSearchCap',
config: {
layout: {
type: 'vbox',
},
items: [
{
xtype: 'fieldset',
title: 'Cap',
instructions: 'Enter Cap',
items: [
{
xtype: 'textfield',
name: 'cap',
placeHolder: 'Cap'
},
{
xtype: 'button',
text: 'Cerca',
ui: 'confirm',
action :'searchCap',
id:'btnSubmitLogin'
}
] // items
}
] // items
}, // config
initialize: function() {
this.callParent(arguments);
console.log('loginform:initialize');
}
});
I hope help you and if you have a dude please let me know. :)
I need create a dataview component with the following structure
Structure
I learned how to create simple text component, but this structure is more difficult.
I use this code, but is only the name field
Ext.define('DEMO.view.product.ListItem', {
extend: 'Ext.dataview.component.DataItem',
xtype: 'product-list-item',
config: {
cls: 'product-list-item',
dataMap: {
getName: {
setHtml: 'name'
}
},
name: {
cls: 'x-name',
flex: 1
},
layout: {
type: 'hbox',
align: 'left'
}
},
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);
}
}
});
Just need to add the other components as the name. For example,
Ext.define('App.view.UserItem', {
extend: 'Ext.dataview.component.DataItem',
xtype: 'useritem',
config: {
cls: 'user-item',
firstName: { cls: 'first-name', flex: 1 },
lastName: { cls: 'last-name', flex: 2 },
layout: { type: 'hbox', align: 'center' },
dataMap: {
getFirstName: { setHtml: 'firstName' },
getLastName: { setHtml: 'lastName' }
}
},
applyFirstName: function(config) {
return Ext.factory(config, Ext.Component, this.getFirstName());
},
updateFirstName: function(newFirstName, oldFirstName) {
if(newFirstName) this.add(newFirstName);
if(oldFirstName) this.remove(oldFirstName);
},
applyLastName: function(config) {
return Ext.factory(config, Ext.Component, this.getLastName());
},
updateLastName: function(newLastName, oldLastName) {
if(newLastName) this.add(newLastName);
if(oldLastName) this.remove(oldLastName);
}
});
For more detail, please visit http://www.sencha.com/blog/dive-into-dataview-with-sencha-touch-2-beta-2/
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.