Search code examples
extjsdata-bindingviewmodel

ExtJS: How do I bind a label to a ViewModel store with a Single record


Please see the following Fiddle: Bind store from a ViewModel to an xtype label

I am NOT able to get the record from my ViewModel's store to display in the xtype: 'label' item of my form.

This should be easy, but alas my brain is not able to work...


Solution

  • There is no way to create a bind descriptor for the first record of a store. You will need to implement a formula for this purpose.

    In your view model:

    formulas: {
        firstTestStoreRecord: {
            bind: '{testStore}',
            get: function(testStore) {
                return testStore.getAt(0);
            }
        }
    }
    

    Then use this in your view:

    bind: {
        html: '<b>{firstTestStoreRecord.test}</b>'
    }
    

    Here is the working fiddle: https://fiddle.sencha.com/#fiddle/25cf&view/editor