Gjslick
22 Dec 2009, 11:03 PM
Ext version tested:
Ext 3.1.0
Adapter used:
ext
css used:
only default ext-all.css
Browser versions tested against:
IE8
FF3.5 (firebug 1.4.5 installed)
Operating System:
WinXP Pro
Description:
Using a directFn with 'paramsAsHash: true' on an Ext.tree.TreeLoader doesn't exactly work as expected. If baseParams are defined when a node is clicked, the data sent to the server from the Direct function looks like this:
data: [ "id-of-clicked-node", { param1: 'value1', param2: 'value2' } ]
I believe that the resulting data should really look like this:
data: [ { param1: 'value1', param2: 'value2', node: "id-of-clicked-node" } ]
Which would maintain consistency with using 'paramsAsHash: true' on Ext.data.DirectProxy's as well.
Test Case:
var myTree = new Ext.tree.TreePanel( {
title: "Tree",
renderTo: Ext.getBody(),
height: 400,
width: 400,
loader: new Ext.tree.TreeLoader( {
directFn: Ext.ss.Test.getTreeNodes,
paramsAsHash: true,
baseParams: {
param1: "hello",
param2: "there"
}
} ),
root: new Ext.tree.AsyncTreeNode( {
text: "Root"
} )
} );
Check the data posted to the server by the Direct function when the root node is clicked.
Debugging already done:
The problem lies in how the params are put together in the TreeLoader
// Ext.tree.TreeLoader
getParams: function(node){
var buf = [], bp = this.baseParams;
if(this.directFn){
buf.push(node.id);
if(bp){
if(this.paramOrder){
for(var i = 0, len = this.paramOrder.length; i < len; i++){
buf.push(bp[this.paramOrder[i]]);
}
}else if(this.paramsAsHash){
buf.push(bp);
}
}
return buf;
}else{
var o = Ext.apply({}, bp);
o[this.nodeParameter] = node.id;
return o;
}
},
We end up with a two element array for 'buf', the first element being the string id of the TreeNode, the second being the baseParams object.
Possible fix:
This code would add the node id into a property of the hashed params object, which would be configurable by the nodeParameter config. This behavior is also what would be expected by reading the docs.
getParams: function(node){
var buf = [], bp = this.baseParams;
if( this.directFn ) {
buf.push( node.id );
if( this.paramOrder ) {
if( bp ) {
for( var i = 0, len = this.paramOrder.length; i < len; i++ ){
buf.push( bp[ this.paramOrder[ i ] ] );
}
}
} else if( this.paramsAsHash ) {
var o = Ext.apply( {}, bp );
o[ this.nodeParameter ] = node.id;
buf = [ o ]; // Reset buf to a 1 element array containing the params object
}
return buf;
} else {
var o = Ext.apply( {}, bp );
o[ this.nodeParameter ] = node.id;
return o;
}
}
It also seems to cover all situations, which are:
paramOrder: undefined, paramsAsHash: false
- Puts the node id string in as the only argument.
paramOrder: undefined, paramsAsHash: true
- Adds the node id string into a property of the hashed params object, specified by the nodeParameter config.
paramOrder: [ array of param names ], paramsAsHash: true/false (true/false, as specifying a paramOrder is supposed to nullify any paramsAsHash value)
- Puts the node id in as the first argument, and appends base params in the paramOrder, after it. It seems that the node id should possibly be appended to the base params instead of prepended to them, but this is the current implementation's order.
Ext 3.1.0
Adapter used:
ext
css used:
only default ext-all.css
Browser versions tested against:
IE8
FF3.5 (firebug 1.4.5 installed)
Operating System:
WinXP Pro
Description:
Using a directFn with 'paramsAsHash: true' on an Ext.tree.TreeLoader doesn't exactly work as expected. If baseParams are defined when a node is clicked, the data sent to the server from the Direct function looks like this:
data: [ "id-of-clicked-node", { param1: 'value1', param2: 'value2' } ]
I believe that the resulting data should really look like this:
data: [ { param1: 'value1', param2: 'value2', node: "id-of-clicked-node" } ]
Which would maintain consistency with using 'paramsAsHash: true' on Ext.data.DirectProxy's as well.
Test Case:
var myTree = new Ext.tree.TreePanel( {
title: "Tree",
renderTo: Ext.getBody(),
height: 400,
width: 400,
loader: new Ext.tree.TreeLoader( {
directFn: Ext.ss.Test.getTreeNodes,
paramsAsHash: true,
baseParams: {
param1: "hello",
param2: "there"
}
} ),
root: new Ext.tree.AsyncTreeNode( {
text: "Root"
} )
} );
Check the data posted to the server by the Direct function when the root node is clicked.
Debugging already done:
The problem lies in how the params are put together in the TreeLoader
// Ext.tree.TreeLoader
getParams: function(node){
var buf = [], bp = this.baseParams;
if(this.directFn){
buf.push(node.id);
if(bp){
if(this.paramOrder){
for(var i = 0, len = this.paramOrder.length; i < len; i++){
buf.push(bp[this.paramOrder[i]]);
}
}else if(this.paramsAsHash){
buf.push(bp);
}
}
return buf;
}else{
var o = Ext.apply({}, bp);
o[this.nodeParameter] = node.id;
return o;
}
},
We end up with a two element array for 'buf', the first element being the string id of the TreeNode, the second being the baseParams object.
Possible fix:
This code would add the node id into a property of the hashed params object, which would be configurable by the nodeParameter config. This behavior is also what would be expected by reading the docs.
getParams: function(node){
var buf = [], bp = this.baseParams;
if( this.directFn ) {
buf.push( node.id );
if( this.paramOrder ) {
if( bp ) {
for( var i = 0, len = this.paramOrder.length; i < len; i++ ){
buf.push( bp[ this.paramOrder[ i ] ] );
}
}
} else if( this.paramsAsHash ) {
var o = Ext.apply( {}, bp );
o[ this.nodeParameter ] = node.id;
buf = [ o ]; // Reset buf to a 1 element array containing the params object
}
return buf;
} else {
var o = Ext.apply( {}, bp );
o[ this.nodeParameter ] = node.id;
return o;
}
}
It also seems to cover all situations, which are:
paramOrder: undefined, paramsAsHash: false
- Puts the node id string in as the only argument.
paramOrder: undefined, paramsAsHash: true
- Adds the node id string into a property of the hashed params object, specified by the nodeParameter config.
paramOrder: [ array of param names ], paramsAsHash: true/false (true/false, as specifying a paramOrder is supposed to nullify any paramsAsHash value)
- Puts the node id in as the first argument, and appends base params in the paramOrder, after it. It seems that the node id should possibly be appended to the base params instead of prepended to them, but this is the current implementation's order.