Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access the context inside an Ember.View?

Tags:

ember.js

I'm trying to get the record ID from the underlying object set on the view object, so I can set it on the view's HTML wrapper. Here's what I'm trying:

// Row in record editing table view.
views.RecordActionTableRowView = Ember.View.extend({
  // Does not work.
  attributeBindings: ['record_id:data-record-id'],
  templateName: 'pult-record-action-table-row',

  init: function () {
    console.log(this);
    // Does not work either. Undefined.
    console.log(this.get('record_id'));
    // Does not work either. Undefined.
    console.log(this.record);
    return this._super();
  }
});

This view is called from a template, so its own template contains the right data, but I can't find it inside the view code. Any suggestions?

like image 396
mikl Avatar asked Dec 05 '25 12:12

mikl


1 Answers

You probably want this.get('context') or this.get('content'). In some circumstances, checking this within didInsertElement may be better than in init, in case the view is created before context is set.

like image 176
Luke Melia Avatar answered Dec 08 '25 06:12

Luke Melia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!