PDA

View Full Version : Problem with store.indexOf() and store.remove()



raj_plays
9 Nov 2011, 10:48 PM
Hi,
After my combo's store has loaded, I add a record to it. This works.
Then I try to find and remove that record. This does not work.
Please help...


var clickableCombo = new Ext.form.ComboBox({
triggerAction: 'all',
forceSelection: true,
store: new Ext.data.ArrayStore({
fields: ['value', 'name'],
data: [
['no', 'No'],
['yes', 'Yes']
]
}),
mode: 'local',
displayField: 'name',
valueField: 'value',
idIndex: 0
});

............................

var clickableComboStore = clickableCombo.getStore();
var newOption = new clickableComboStore.recordType({
value: 'call',
name: 'Call'
});

//This works
clickableComboStore.add(newOption);

//These 2 lines don't work.. indexOf() always returns -1
if (clickableComboStore.indexOf(newOption) != -1) {
clickableComboStore.remove(newOption);
}

mitchellsimoens
10 Nov 2011, 4:47 AM
Just tried this and it works 100%:


var store = new Ext.data.ArrayStore({
fields: ['value', 'name'],
data: [
['no', 'No'],
['yes', 'Yes']
]
});

var rec = new store.recordType({
value : 'call',
name : 'Call'
});

store.add(rec);

console.log(store.getCount()); // returns 3, correct!
console.log(store.indexOf(rec)); // returns 2, correct!
store.remove(rec);
console.log(store.getCount()); // returns 2, correct!

raj_plays
10 Nov 2011, 6:45 AM
Thank you so much, Mitchell.
I realized my mistake.
While using indexOf(), i was using another record object, not the one that I used in add().
I thought that since both objects have the same data, it would work.

I am wise now. I use store.findExact instead of indexOf.