PDA

View Full Version : How to map a fileld to a component in componentView item?



linuxyf
8 Dec 2011, 5:18 PM
refer to Kiva code:

Ext.define('Kiva.view.LoansListItem', { extend: 'Ext.dataview.DataItem',
xtype : 'loanslistitem',
requires: ['Ext.Img'],


config: {
dataMap: {
getName: {
setHtml: 'name'
}
},


baseCls: Ext.baseCSSPrefix + 'list-item',


name: {
cls: 'name'
}
},


applyName: function(config) {
return Ext.factory(config, Ext.Component, this.getName());
},


updateName: function(newName) {
if (newName) {
this.add(newName);
}
}

i know how to map a field in store to a direct child component of dataitem, but if i have a complicated layout in dataitem. for example a button as following code: how to map a field (testid) to button (tableidbtn).


Ext.define('ShopSystem.view.TestListItem', {
extend: 'Ext.dataview.DataItem',
xtype : 'testlistitem',

config: {
dataMap: {
//? how to map to
},


baseCls: Ext.baseCSSPrefix + 'list-item',
cls: 'SheetSelectItemCls',
items: [{
xtype: 'panel',
layout: {
type: 'hbox',
align: 'middle',
pack: 'end'
},
items:[
{
xtype: 'spacer',
width: 10
},
{
xtype: 'button',
name: 'tableidbtn',
ui: 'normal'
}
]
}
],



applyTable_no: function(config) {
// how to code here
},


updateTable_no: function(newName) {
if (newName) {
// how to code here
}
},

sometimes, i want to show a modified fieldvalue, for example, the fieldvalue is 5, i want to show fieldvalue + 5 (10) in mapping button, how to implement it?

rdougan
8 Dec 2011, 5:49 PM
The dataMap is just calling a specified function with the new value. So it is as simple as creating a new function, and within that function doing whatever you need.


config: {
dataMap: {
doSomething: 'name'
}
},

doSomething: function() {
...
}

Edit

Actually, I'm wrong. You cannot do that. But it would be incredibly handy.

linuxyf
8 Dec 2011, 6:07 PM
Edit

Actually, I'm wrong. You cannot do that. But it would be incredibly handy.

What do you mean? what you said is practicable?

follow your advice, doSomething function can't be called.

rdougan
8 Dec 2011, 7:29 PM
You cannot do that in PR2, however I added a ticket to review this and possibly integrate it.

SparkDesign
22 Dec 2011, 2:12 AM
Any progress regarding this issue?

rdougan
22 Dec 2011, 3:09 PM
There is a ticket for it already and if implemented, it will be in for the next release.

jsweere
7 Feb 2012, 7:39 AM
Was this item indeed implemented in PR3?

rdougan
7 Feb 2012, 10:57 AM
Unfortunately not. This is because there is no way to check if the method you have specified in your dataMap is a gettor or just a normal method.

To get around this, you can override the updateRecord method in your dataitem, which is passed the newRecord and the oldRecord. Ensure you callParent though.