O'Reilly logo

Ext JS 4 Web Application Development Cookbook by Stuart Ashworth, Andrew Duncan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Saving and loading data with HTML5 Local Storage

Ext JS 4 provides a new LocalStorageProxy (Ext.data.proxy.LocalStorage) which allows you to save data to the client's browser with the HTML5 localStorage API.

This recipe demonstrates how to use this proxy to save and retrieve your user's settings.

How to do it...

  1. Start by defining the UserSetting model with the following fields. We are going to assign userID as the idProperty and you will see why this is important later.

    Note

    If we do not assign our own id field the Ext.data.Model will create one automatically for us called id.

    Ext.define('UserSetting', { extend: 'Ext.data.Model', idProperty: 'userID', fields: [{ name: 'userID', type: 'int' }, { name: 'fontSize', type: 'string' }, { name: 'theme', type: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required