1. #1
    Ext User
    Join Date
    Oct 2010
    Posts
    1
    Vote Rating
    0
    Akhenaten is on a distinguished road

      0  

    Default Saving List data to local storage

    Saving List data to local storage


    Hello all,

    I have looked around the forums for this issue and didn't come across any pertinent posts, but feel free to direct me to a previous thread if I missed one.

    I am attempting to take a List backed by a JSON store and save that data to local storage by instantiating another store. I found a post on Ed Spencer's blog talking about local storage in general and tried to apply it to my app, and although the code doesn't throw any errors, it doesn't send the data to local storage either. I am very new to not just Sencha Touch, but also to web application development, so please pardon my likely easily-solvable problem.

    I have a model named "Patient" that contains various strings to describe a patient (name, rm_num, sex, dob, etc).

    The List object's data is not loaded automatically, but rather on button press which loads the data from an Ajax proxy that receives JSON from a server-side PHP script. Here is the button code:

    Code:
    {
    	text: 'Load (Remote)',
    	ui: 'action',
    	centered: true,
    	handler: function() {
    		patList.getStore().load();
    	}
    },
    This button does work and loads the list appropriately when clicked. Once loaded, I want to "save" this data to local storage. Here is the code for the save button:

    Code:
    {
    	text: 'Save',
    	ui: 'action',
    	centered: true,
    	handler: function() {
    		var localStore = new Ext.data.Store({
    			proxy: new Ext.data.LocalStorageProxy({
    				id: 'patients'
    			}),
    			model: 'Patient'
    		});
    		localStore.sync();
    	}
    },
    When this "save" button is clicked, no error is thrown, but the data is not saved to local storage. Looking in Safari's web inspector, I see a "patients" key that is created (which I assume to come from the id I provided to the localStorageProxy), but there are no other keys or values. In my previous testing I saw how local storage writes additional keys with [id]-1 and then writes the data to the value for that key.

    Please let me know if other code or debugging information is needed.

    Thanks very much,
    Ben Gohlke

  2. #2
    Sencha User Mis63's Avatar
    Join Date
    Aug 2010
    Location
    Clermont-Ferrand, France
    Posts
    42
    Vote Rating
    0
    Mis63 is on a distinguished road

      0  

    Default


    It's normal. Your localStore is empty.
    You just created a new Store that can contain records of model Patient. Before to sync your localStore, you need to fill it with records of your store attached to your list.

  3. #3
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Try localStore.addAll(patList.getStore().getRange()) before localStore.sync(). This will grab all the Model instances from the first store and add them into the second
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  4. #4
    Sencha User
    Join Date
    Jul 2009
    Posts
    35
    Vote Rating
    1
    MrRoyce is on a distinguished road

      0  

    Default


    I got an undefined method when I tried to use addAll(). I think it should be the add() method. However, it doesn't seem to store the 'hasMany' relationship of my model. The model has a parent/child relationship defined and it all works well in the main application.

    I have a store that retrieves data and I simply add the returned records to the localStore, but in the Chrome storage inspector, all I see is the parent data. I know the entire parent/child relationship is being returned because the rest of my application (that doesn't rely on local storage yet) works correctly. I cannot retrieve the child data when I do a load() on the localStore. I only get back the parent data.

    edit: The data does seem actually exist in the local browser storage. When I clear the cache, and go to about:cache in Chrome, the data seems to be there. Odd that it doesn't show in the Chrome browser inspector.
    Last edited by MrRoyce; 17 Dec 2010 at 7:53 AM. Reason: New Information

  5. #5
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    Quote Originally Posted by MrRoyce View Post
    I got an undefined method when I tried to use addAll().
    Ah yes - that's a MixedCollection method. Getting my APIs mixed up

    Store will currently only save the single Model it is configured with - e.g. it won't save associated Model instances. Usually this is what you want when saving to a server side, though perhaps not as useful as it could be if you're trying to persist lots of data locally...
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

  6. #6
    Sencha User
    Join Date
    Jul 2009
    Posts
    35
    Vote Rating
    1
    MrRoyce is on a distinguished road

      0  

    Default


    Quote Originally Posted by edspencer View Post
    ... Getting my APIs mixed up
    I know that feeling!

    I thought the whole point of the model with the hasMany relationship was to allow the serilization/deserialization of objects. I just assumed that the entire process would just seamlessly work, but now I have to iterate through my multilevel model to do my own serialization?

    Hopefully this is on the drawing board for a future release.

  7. #7
    Sencha - Community Support Team edspencer's Avatar
    Join Date
    Jan 2009
    Location
    Palo Alto, California
    Posts
    1,939
    Vote Rating
    7
    edspencer is a jewel in the rough edspencer is a jewel in the rough edspencer is a jewel in the rough

      0  

    Default


    At the moment it won't save your associated model data. This is probably easier on the client side than the server side... it's on my mind to add something that does this but no firm timeframe as yet
    Ext JS Senior Software Architect
    Personal Blog: http://edspencer.net
    Twitter: http://twitter.com/edspencer
    Github: http://github.com/edspencer

Similar Threads

  1. Local Storage
    By tomalex0 in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 20 Dec 2010, 6:24 AM
  2. [Solved] Nested List Example on Local Machine Poses Errors
    By busybee in forum Sencha Touch 1.x: Discussion
    Replies: 2
    Last Post: 12 Oct 2010, 11:14 AM
  3. Replies: 2
    Last Post: 3 Jun 2010, 10:53 AM
  4. client side data storage without cookies?
    By dolittle in forum Community Discussion
    Replies: 21
    Last Post: 8 Aug 2008, 9:41 AM
  5. idea: local storage using Flash Shared objects
    By PromaneX in forum Community Discussion
    Replies: 0
    Last Post: 2 Jun 2008, 4:53 AM

Thread Participants: 3

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar