PDA

View Full Version : Problem for filtering in MixedCollection



Sakson
2 Jul 2009, 4:25 AM
Please i use MixedCollection for filtering
by i get this error for last instruction in firebug :
getTestStatus().query("name", "D").filter("value", "N").first() is undefined


Here is my code :


function getTestStatus() {
/*TODO use ajax request
* */
return new Ext.data.JsonStore({
fields : [{
name : 'id',
type : 'int'
}, {
name : 'name',
type : 'string'
}, {
name : 'value',
type : 'string'
}, {
name : 'title',
type : 'string'
}],
data : {
status : [{
id : 0,
name : 'D',
value : 'C',
title : 'Cancelled'
},{
id : 1,
name : 'D',
value : 'O',
title : 'Opened'
},
{
id : 2,
name : 'D',
value :'S',
title : 'Signed'
},
{
id : 3,
name : 'D',
value :'R',
title : 'Refused by EVT'
},
{
id : 4,
name : 'D',
value :'L',
title : 'Closed'
},
{
id : 5,
name : 'D',
value :'M',
title : 'Removed'
},
{
id : 6,
name : 'F',
value :'N',
title : 'Not Covered'
},
{
id : 7,
name : 'F',
value :'P',
title : 'Partially Covered'
},
{
id : 8,
name : 'F',
value :'C',
title : 'Covered'
},
{
id : 9,
name : 'T',
value :'N',
title : 'Not Available'
},
{
id : 10,
name : 'T',
value :'X',
title : 'Not Applicable N/A'
},
{
id : 11,
name : 'T',
value :'P',
title : 'Partially Available'
},
{
id : 12,
name : 'T',
value :'A',
title : 'Available'
},
{
id : 13,
name : 'C',
value :'D',
title : 'Draft'
},
{
id : 14,
name : 'C',
value :'V',
title : 'Validated'
},
{
id : 15,
name : 'C',
value :'C',
title : 'Canceled'
},
{
id : 16,
name : 'L',
value :'N',
title : 'Not Closed'
},
{
id : 17,
name : 'L',
value :'Y',
title : 'Closed'
}]
},
root : 'status'
});
};
test = getTestStatus().query('name','D').filter('name','D').first().get('id');


What's wrong :-?? Please help.

BitPoet
2 Jul 2009, 6:37 AM
You don't have an item with a name of 'D' and a value of 'N' in your collection, therefore first() returns null. You need to check if your filter returned hits at all.


var res = getTestStatus().query("name", "D").filter("value", "N");
if( res.getCount() > 0 ) {
test = res.first();
}