Results 1 to 5 of 5

Thread: How do I reload data for just one item in my store?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Sep 2011
    Vote Rating

    Default Answered: How do I reload data for just one item in my store?

    I have a list of items in a store that I hit on my API endpoint like so:

    When I navigate to this item I'd like to be able to either give the user a chance to reload the data (from the API) manually, or do it automatically myself.

    Is this possible with Sencha? How can I accomplish this?

    Additionally, if I hit the single URL for one of these things like: returns associated nested data. I'd like to reload this associated data as well.

    I can't find a "reload", "refresh", "load", or any other type of method that will allow me to do this in the Model API.


  2. Screw it...hacked together a 'reload' method that will reload item data from its single endpoint, along with JSON associations.

    Here goes for anyone that runs into the same issue, which I suspect will be A LOT OF PEOPLE.

    Ext.define('CbMobile.model.Base', {
      extend: '',
      // Reloads a single object's data, including assocations.
      reload: function(config, scope) {
        var me = this;
        var proxy = me.getProxy(),
          idProperty = me.getIdProperty(),
          record = null,
          params = {},
          id = me.getId(),
        scope = scope || (config && config.scope) || me;
        if (Ext.isFunction(config)) {
          config = {
            callback: config,
            scope: scope
        params[idProperty] = id;
        config = Ext.apply({}, config);
        config = Ext.applyIf(config, {
          action: 'read',
          params: params
        operation  = Ext.create('', config);
        if (!proxy) {
          Ext.Logger.error('You are trying to reload a model that doesn\'t have a Proxy specified');
        callback = function(operation) {
          if (operation.wasSuccessful()) {
            record = operation.getRecords()[0];
            // Have to read the raw data for associations from response,
            // because it's not returned or decoded in the 'record' for some stupid reason.
            var response = operation.getResponse();
            var responseRawJson = Ext.JSON.decode(response.responseText); 
            Ext.callback(config.success, scope, [record, operation]);
          } else {
            Ext.callback(config.failure, scope, [record, operation]);
          Ext.callback(config.callback, scope, [record, operation]);
        };, callback, me);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts