How to get model property in className of ItemView element?

In my application, I need to display ul users with their identifiers in the class attribute of li. S I tried to do it as follows:

Marionette.ItemView.extend({
    tagName: 'li',
    className: this.model.get('user_id'),
        template: userTpl
});

But that did not work. Can this be achieved in any other way?

+4
source share
3 answers

Can't you do something like that?

className: function(){
  return this.model.get('user_id');
}
+2
source

You can put this logic in the onBeforeRender method

Marionette.ItemView.extend({
    tagName: 'li',
    template: userTpl,
    onBeforeRender: function(){
          this.className = this.model.get('user_id'),
    }
});
+1
source

setElement, :

Backbone DOM, setElement, $el .

0

Source: https://habr.com/ru/post/1530956/


All Articles