PDA

View Full Version : Finding a record?



bstras21
22 Dec 2011, 8:18 AM
Hello, I am lopping a store to find a record and I can't seem to get it working correctly:



me.offlineStore.load();
Ext.Array.each(loadRecords, function(name, index) {
var count = index + 1;


if(!me.offlineStore.findRecord('ID', count)){
console.log('record DOES NOT exists'+ count);
}else{
console.log('record exists'+ count);
}



});


Now when I check my log (No data is in the store yet) I get this:

record DOES NOT exists1Store.js
:30record DOES NOT exists2Store.js
:30record DOES NOT exists3Store.js
:34record exists4Store.js
:30record DOES NOT exists5Store.js
:30record DOES NOT exists6Store.js
:30record DOES NOT exists7Store.js
:30record DOES NOT exists8Store.js
:30record DOES NOT exists9Store.js
:30record DOES NOT exists10Store.js
:30record DOES NOT exists11Store.js
:30record DOES NOT exists12Store.js
:30record DOES NOT exists13Store.js
:30record DOES NOT exists14Store.js
:30record DOES NOT exists15Store.js
:30record DOES NOT exists16Store.js
:30record DOES NOT exists17Store.js
:30record DOES NOT exists18Store.js
:30record DOES NOT exists19Store.js
:30record DOES NOT exists20Store.js
:34record exists21Store.js
:30record DOES NOT exists22Store.js
:30record DOES NOT exists23Store.js
:30record DOES NOT exists24Store.js
:30record DOES NOT exists25Store.js
:34record exists26Store.js
:30record DOES NOT exists27Store.js
:30record DOES NOT exists28Store.js
:30record DOES NOT exists29Store.js
:30record DOES NOT exists30Store.js
:30record DOES NOT exists31Store.js
:30record DOES NOT exists32Store.js
:30record DOES NOT exists33Store.js
:34record exists34Store.js
:30record DOES NOT exists35Store.js
:30record DOES NOT exists36Store.js
:30record DOES NOT exists37Store.js
:30record DOES NOT exists38Store.js
:30record DOES NOT exists39Store.js
:30record DOES NOT exists40Store.js
:30record DOES NOT exists41Store.js
:34record exists42Store.js
:30record DOES NOT exists43Store.js
:30record DOES NOT exists44Store.js
:30record DOES NOT exists45Store.js
:30record DOES NOT exists46Store.js
:34record exists47Store.js
:30record DOES NOT exists48Store.js
:30record DOES NOT exists49Store.js
:30record DOES NOT exists50Store.js
:30record DOES NOT exists51Store.js
:34record exists52Store.js
:34record exists53Store.js
:34record exists54

I'm not sure what I'm doing wrong? Records should not be existing (I've removed the store many times and ran is with the same results). Should I be using a different method to check a store for a record? Thanks!

mitchellsimoens
22 Dec 2011, 8:23 AM
localstorage does load too fast so you still need to think async. Try looping through the loadRecords on the load event.

bstras21
22 Dec 2011, 9:16 AM
I went and put the loop in the load callback function but I get the same results:



me.offlineStore.load({
scope : this,
callback: function(records, operation, success) {
Ext.Array.each(loadRecords, function(name, index) {
var count = index + 1;
if(!me.offlineStore.findRecord('ID', count)){
console.log('record DOES NOT exists'+ count);
}else{
console.log('record exists'+ count);
}
});



}
});



record exists1
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists2
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists3
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists4
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists5
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists6
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists7
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists8
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists9
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists10
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists11
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists12
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists13
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists14
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists15
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists16
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists17
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists18
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists19
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists20
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists21
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists22
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists23
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists24
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists25
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists26
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists27
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists28
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists29
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists30
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists31
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists32
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists33
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists34
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists35
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists36
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists37
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists38
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists39
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists40
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists41
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists42
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists43
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists44
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists45
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists46
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists47
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists48
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists49
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists50
Store.js:32 (http://127.0.0.1:8000/app/custom/Store.js)record DOES NOT exists51
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists52
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists53
Store.js:35 (http://127.0.0.1:8000/app/custom/Store.js)record exists54

bstras21
22 Dec 2011, 9:43 AM
I believe you are correct that it is a timing issue, I tied it to a button and it seems to work, thanks!