JkSuf
JkSuf

Reputation: 343

EXTJS 5 Can I have a tree store in stores property of view model?

I have this simple mvvm example: https://fiddle.sencha.com/#fiddle/j8m

When I console.log the viewModel from the controller, stores appear in the data attribute, calling viewModel.getStores() returns me null. I don't get it :/...

Here is the same code as in the fiddle:

Ext.define('MainViewModel', {
    extend: 'Ext.app.ViewModel',
    alias: 'viewmodel.mainviewmodel',

    stores: {
        todoAccountsStore: {
            type: 'tree'
        },
        skipAccountsStore: {
            type: 'tree'
        }
    }
});

Ext.define('MainViewController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.mainviewcontroller',

    init: function() {
        console.log(this.getViewModel());
    }
});

Ext.define('MainView', {
    extend: 'Ext.panel.Panel',
    xtype: 'view-main',

    controller: 'mainviewcontroller',

    viewModel: {
        type: 'mainviewmodel'
    }
});

var test = Ext.create('MainView', {
    renderTo: Ext.getBody()
});

Upvotes: 0

Views: 1096

Answers (1)

Monica Olejniczak
Monica Olejniczak

Reputation: 1156

To retrieve your stores, you can use the following code within your controller:

var viewModel = this.getViewModel();
var todo = viewModel.getStore('todoAccountsStore');
var skip = viewModel.getStore('skipAccountsStore');

Based on this thread they state that the getStores method was intended to be private. I presume the docs have still has not been updated to represent this.

Upvotes: 1

Related Questions