Results 1 to 5 of 5

Thread: ViewModel Stores, Formulas: Is it possible bind record of Store by Model-Id?

  1. #1

    Default ViewModel Stores, Formulas: Is it possible bind record of Store by Model-Id?

    Is it possible bind record of Store by Model-Id instead of referring to the index?
    The example below works if bind specific index:env:'{environments.data.items.2}'

    However, is it possible using Model-Id, as it makes the code maintainable that way.
    :

    Code:
        Ext.define('EnvironmentStore', {
            extend: 'Ext.data.Store',
            storeId: 'environmentStore',
            alias: 'store.environment',
            model: 'EnvironmentModel',
            proxy: {
                type: 'ajax',
                url: 'environment',
                method: 'GET',
                reader: {
                    type: 'json',
                    rootProperty: 'root'
                }
            }
        });
    
        Ext.define('EnvironmentModel', {
            extend: 'Ext.data.Model',
            idProperty: 'variableName',
            fields: [
                { name: 'variableName', type: 'string' },
                { name: 'variableValue', type: 'string' }
            ]
        });
    
    
    
        Ext.define('EnvironmentVM', {
            extend: 'Ext.app.ViewModel',
            alias: 'viewmodel.environment',
    
            stores: {
                environments: {
                    type: 'environment',
                    autoLoad: true,
                    session: true
                }
            },
    
            formulas: {
                env: {
                    bind: {
                        env: '{environments.data['UAT']}',
                        deep: true
                    },
                    get: function (link) {
                        if(!link.env) {
                            return null;
                        } else { returnlink.env }
    
    
                    }
                }
            }
    
        });
    

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,257
    Answers
    759
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3

    Default

    This approach binds all the store into formula and with deep true which looks heavy.
    I was wondering if there was a way using bind descriptor {} to target only one record by Id and with deep true?

  4. #4
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,257
    Answers
    759

    Default

    It's not heavy, it executes a look by id (constant time) when the data in the store changes, or the id changes.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  5. #5
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379
    Answers
    3997

    Default

    The id lookup (via getById) is also a simple object key lookup, it doesn't loop thru all the records to find an id which could then be considered "heavy".
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

Similar Threads

  1. Replies: 2
    Last Post: 24 Aug 2015, 5:36 PM
  2. Replies: 4
    Last Post: 20 Apr 2015, 8:28 AM
  3. Replies: 0
    Last Post: 11 Feb 2015, 9:57 PM
  4. Can't Bind to Stores in ViewModel
    By benoror in forum Ext 5: Q&A
    Replies: 1
    Last Post: 8 Oct 2014, 10:30 AM
  5. Replies: 0
    Last Post: 19 Aug 2014, 12:13 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
  •