PDA

View Full Version : Making a button work, that is on the disclose panel from a list.



coletek
4 Dec 2012, 3:09 PM
Ok, when I click on a item in a list, via the disclose feature. The page that is disclosured, contains a button which I need to hook up for item disclosured. The button has a id option, but I can not assign the record id via
id: '{id}', nor can I work out how to get the record id, in the controller callback, so I'm unsure how to do this. Any ideas? See the code below.

I have the following model:



Ext.define('test.model.Comp', {
extend: 'Ext.data.Model',


config: {


fields: [
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' }
]


}


});


And I have the following store:



Ext.define('test.store.Comps', {
extend: 'Ext.data.Store',
config: {
storeId : 'compsstore',
model: 'test.model.Comp',
sorters: 'name',
autoLoad: true,
proxy: {
type: 'ajax',
url: 'backend/get_comps.php',
reader: {
type: 'json',
rootProperty: 'data'
}
}
}
});


And I have the following list view:



Ext.define('test.view.CompsList', { extend: 'Ext.List',
xtype: 'compslist',
config: {
title: 'Comps',
autoLoad: true,
itemTpl: '{name}',
store: 'compsstore',
onItemDisclosure: true
}
});


Then I have the following item for disclosure:



Ext.define("test.view.CompDetails", {
extend: 'Ext.Panel',
xtype: 'compdetailspanel',


config: {
styleHtmlContent: true,
scrollable: 'vertical',


tpl: '<b>Compeitition ID:</b> {id}<br /> <b>Compeitition Name:</b> {name}<br />',


items: [
{
id: 'joinComp',
xtype: 'button',
ui: 'confirm',
margin: 40,
text: 'Join This Comp'
}
]
}


});


Which is controlled via the controller:



Ext.define('test.controller.Main', {
extend: 'Ext.app.Controller',


config: {
refs: {
main: 'mainpanel',
account: 'accountnav',
joinComp: '#joinComp'
},
control: {
'compslist': {
disclose: 'showComp'
},
'joinComp': {
tap: 'joinComp'
}
}
},


showComp: function(list, record) {
console.log(record);
this.getAccount().push({
xtype: 'compdetailspanel',
title: 'Comp \'' + record.get('name') + '\'',
data: record.data
});
},


joinComp: function(dataview, index) {
// how do I get the id of the record? So I can call a php script to act on it.
}

});


But as the comment above says, how do I get the ID from the record we have disclosed?

coletek
6 Dec 2012, 4:20 AM
The answer can be found within:

http://www.sencha.com/blog/developing-mobile-applications-with-forcecom-and-sencha-touch-part-2/