bowa
17 Oct 2007, 12:41 AM
I don't know if this is really a bug ... its more like an enhancement.
in View.js this is how the prepareData method is defined:
/**
* Function to override to reformat the data that is sent to
* the template for each node.
* @param {Array/Object} data The raw data (array of colData for a data model bound view or
* a JSON object for an UpdateManager bound view).
*/
prepareData : function(data){
return data;
},
its called in these methods:
refresh:
var data = this.prepareData(records[i].data, i, records[i]);
onUpdate:
this.tpl.insertBefore(n, this.prepareData(record.data));
onAdd:
var d = this.prepareData(records[i].data);
you can see in 'refresh' there are 3 parameters passed on, while in onUpdate and onAdd, only 1
in my extended View i overwrite these method and change the calls to
onUpdate:
this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
onAdd:
var d = this.prepareData(records[i].data, index, records[index]);
like this i can overwrite the prepareData function and i have more information available in that method to add logic ...
prepareData : function(data, index, record){
data.index = index;
return data;
},
here i just added the 'index' parameter to the data object so i can use it in my template.
in View.js this is how the prepareData method is defined:
/**
* Function to override to reformat the data that is sent to
* the template for each node.
* @param {Array/Object} data The raw data (array of colData for a data model bound view or
* a JSON object for an UpdateManager bound view).
*/
prepareData : function(data){
return data;
},
its called in these methods:
refresh:
var data = this.prepareData(records[i].data, i, records[i]);
onUpdate:
this.tpl.insertBefore(n, this.prepareData(record.data));
onAdd:
var d = this.prepareData(records[i].data);
you can see in 'refresh' there are 3 parameters passed on, while in onUpdate and onAdd, only 1
in my extended View i overwrite these method and change the calls to
onUpdate:
this.tpl.insertBefore(n, this.prepareData(record.data, index, record));
onAdd:
var d = this.prepareData(records[i].data, index, records[index]);
like this i can overwrite the prepareData function and i have more information available in that method to add logic ...
prepareData : function(data, index, record){
data.index = index;
return data;
},
here i just added the 'index' parameter to the data object so i can use it in my template.