View Full Version : Localstorage question

28 Jul 2010, 8:08 PM
I am using localstorage and have a question about how to update the data.

My code looks like this.
The problem is, the "addSomeRecords" function is not doing its job.

Any idea whats wrong here?

// Model for my store //
Ext.regModel('mApp', {
fields: [
{name: 'name', type: 'string'},
{name: 'assets'}, // This will be stored as Array
{name: 'something'} // This will be stored as Array

Ext.onReady(function() {
// Not sure how my localstorage key should be initialized.//
//localStorageKey: 'myAppName';
//set the store up
var myStore = new Ext.data.Store({
proxy: new Ext.data.LocalStorageProxy({
id: 'my-App'
model: 'mApp'


// This function will be used to update records later //
updateRecords = function(rec, index, data){
//var oldRec = myStore.get(rec);
// oldRec would be an array
//var recToUpdate = oldRec[index];

// Function to add records
addSomeRecords = function(name, a1, a2){
myStore.add('name', name);
myStore.add('assets', a1);
myStore.add('something', a2);

scope: this,
callback: function(records) {
// Do something
if (records.length == 0) {
alert ('No Data');
// If no records are found, lets add some dummy data for testing.
addSomeRecords("Some dummy string", ["a", "b", "c"], ["1111", "2222", "3333"]);
} else {
alert ('Has Data');

28 Jul 2010, 8:24 PM
Where did you get the parameters for add, because that's not what the docs have:


28 Jul 2010, 9:16 PM
thanks for pointing that out.

Now I change it to this:

myStore.add({name: name}, {assets: a1},{something: a2});

I am not sure is 'add' or 'insert' is the right thing to do.

Basically I have a Model, A store based on that model, and now I want to populate the store with data and later update that data as my app gets used.

Is this right thing to do?