/ext-4.0.7/docs/guides/data/examples/simple_store/app.js

https://bitbucket.org/srogerf/javascript · JavaScript · 38 lines · 24 code · 2 blank · 12 comment · 0 complexity · b4b6f8dc1db7f1f9b586cab6ebbcc636 MD5 · raw file

  1. /**
  2. * @example Simple Store
  3. *
  4. * This example creates a simple store that auto-loads its data from an ajax
  5. * proxy. Since we are only dealing with data there is no UI, so a global
  6. * variable called "userStore" is created which is an instance of
  7. * {@link Ext.data.Store}.
  8. *
  9. * Feel free to experiment with the "userStore" object on the console command
  10. * line. For example - `userStore.getCount()` gets the total number of records
  11. * in the store. `userStore.getAt(0)` gets the record at index 0.
  12. */
  13. Ext.define('User', {
  14. extend: 'Ext.data.Model',
  15. fields: [
  16. {name: 'id', type: 'int'},
  17. {name: 'name', type: 'string'}
  18. ]
  19. });
  20. var userStore;
  21. Ext.require('Ext.data.Store');
  22. Ext.onReady(function() {
  23. userStore = Ext.create('Ext.data.Store', {
  24. model: 'User',
  25. autoLoad: true,
  26. proxy: {
  27. type: 'ajax',
  28. url: 'data/users.json',
  29. reader: {
  30. type: 'json',
  31. root: 'users',
  32. successProperty: 'success'
  33. }
  34. }
  35. });
  36. });