Results 1 to 3 of 3

Thread: Can't listen to store inside a view model

  1. #1
    Sencha User
    Join Date
    Aug 2014
    Posts
    21
    Vote Rating
    2
      0  

    Default Can't listen to store inside a view model

    I usually use the basic binding feature of the architect to listen to the "exception" event.

    I am here however confronted to a case where my store is in the view model:

    Code:
    Ext.define('myProject.view.MyViewModel', {
        extend: 'Ext.app.ViewModel',
        alias: 'viewmodel.mymodel',
    
        requires: [
            'Ext.data.Store',
            'Ext.data.proxy.Ajax',
            'Ext.data.reader.Json',
        ],
    
        data: {},
    
        stores: {
            MyStore: {
                autoLoad: false,
                model: 'myProject.model.MyModel',
                sortOnLoad: false,
                proxy: {
                    type: 'ajax',
                    extraParams: {
                        
                    },
                    reader: {
                        type: 'json',
                        messageProperty: 'message',
                        rootProperty: 'data'
                    }
                }
            }
        }
    
    });
    Now I would like to have an exception handler, so the only option available to me in this context (basic event binding not being available) is: `View Controller Event Binding`

    My proxy thus becomes:

    Code:
                proxy: {
                    type: 'ajax',
                    extraParams: {
                        
                    },
                    reader: {
                        type: 'json',
                        messageProperty: 'message',
                        rootProperty: 'data'
                    },
                    listeners: {
                        exception: 'onAjaxException'
                    }
                }
    Which gives me the following exception when I try running the app:

    [E] Ext.util.Event.getFireInfo(): No method named "onAjaxException" on Ext.data.proxy.Ajax

    Why? Because seeing is believing architect decided to create the handler in the view controller (instead of the proxy which is inside the view model's stores):


    Code:
    Ext.define('myProject.view.MyViewController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.mycontroller',
    
        onAjaxException: function(proxy, request, operation, eOpts) {
            console.log('hello');
        }
    
    });
    So the onAjaxException handler created by the architect is not found by the store's proxy (it's in a different file!).


    Interestingly enough, if I manually create a Function in the proxy called "onAjaxException" it *does* run, but I can't get read of the wrongly created homonym in the view controller

    Pierre

    EDIT: forgotten to attach my config:

    Sencha Architect

    version: 3.2.0.75
    channel: 3.2-stable
    platform: 1.4.1.960
    cmd: 5.1.3.61
    framework: Ext JS 5.1.x

  2. #2
    Sencha Premium User
    Join Date
    Aug 2016
    Location
    Las Vegas, NV
    Posts
    19
    Vote Rating
    3
      0  

    Default

    I've just confirmed that this is still a problem in 6.2. Did you get around the problem by manually setting a listener during the afterrender or similar event?

  3. #3
    Sencha User
    Join Date
    Apr 2013
    Posts
    91
    Vote Rating
    7
      0  

    Default

    still a problem in 6.5.2

Similar Threads

  1. Replies: 1
    Last Post: 27 Sep 2014, 6:35 AM
  2. View model binding inside a template
    By fruel in forum Ext 5: Q&A
    Replies: 1
    Last Post: 17 Apr 2014, 8:02 AM
  3. Replies: 2
    Last Post: 7 Jun 2012, 9:02 AM
  4. Replies: 1
    Last Post: 30 Mar 2012, 5:21 AM

Tags for this Thread

Posting Permissions

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