Last Updated: February 25, 2016
·
1.988K
· rodnaph

ExtJS XTemplate with Models

Unfortunately XTemplate templates in ExtJS 4 have no support for accessing the models your give them to iterate over. They're all converted to plain objects first.

Maddening... :E

So if you need to get some custom data into your templates that you'd usually call a model method for (eg. model.getThumbnailUrl() or something...) you need to override the getAssociatedData() method.

Ext.define('MyApp.data.MyModel', {
  extend: 'Ext.data.Model',
  getAssociatedData: function() {
    return {
      foo: 'bar',
      thumbUrl: this.getThumbnailUrl()
    };
  }
}

I don't know where else this is used though... so take care!

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside