1

私のビューは、Redactor WYSIWYG エディターを初期化しています。また、ルートに直接入るときは問題なく機能しますが、あるルートからこのルートに戻ることはありません。つまり から//documents/1

これは私が得るエラーです:

Uncaught Error: Something you did caused a view to re-render after it
rendered but before it was inserted into the DOM. 

意見:

ビューにもいくつかコメントをしました。

App.RedactorView = Ember.TextArea.extend({
  tagName: 'div',
  init: function() {
    this._super();
    this.on("didInsertElement", this, this._updateElementValue);
  },
  _updateElementValue: Ember.observer(function() {
    var value = Ember.get(this, 'value'),
        $el = this.$();

    if ($el && value !== $el.getCode()) {
      $el.setCode(value);
    }
  }, 'value'),
  _elementValueDidChange: function() {
    Ember.set(this, 'value', this.$().getCode());
  },
  didInsertElement: function() {
    console.log('didInsert');
  },
  willInsertElement: function() {
    // these two lines causes the error when coming from other route, but works fine when accessed directly
    var test = this.$().attr('class');
    this.$().redactor(); 

    // returns fine when accessed directly, otherwise not available, see explanation above
    console.log(this.$().getCode());
  }
});

コードを移動しようとしましdidInsertElementたが、以前にアクセスしていた Redactor 機能へのアクセスを失います。

  didInsertElement: function() {
     // will not throw any errors when transitioned from other route
    var test = this.$().attr('class');
    this.$().redactor(); 

    // Uncaught TypeError: Cannot call method 'getCode' of undefined
    console.log(this.$().getCode());
  },

何か案が?

4

1 に答える 1

0

So it seems like being lazy and extending Ember.TextArea was a bad idea. I guess one of its subclasses mess up the work jQuery does.

I changed my View and now it's working.

App.RedactorView = Ember.View.extend({
  tagName: 'div',
  init: function() {
    this._super();

    this.on("focusOut", this, this._elementValueDidChange);
    this.on("change", this, this._elementValueDidChange);
    this.on("paste", this, this._elementValueDidChange);
    this.on("cut", this, this._elementValueDidChange);
    this.on("input", this, this._elementValueDidChange);
  },
  _updateElementValue: Ember.observer(function() {
    var value = Ember.get(this, 'value'),
        $el = this.$();

    if ($el && value !== $el.getCode()) {
      $el.setCode(value);
    }
  }, 'value'),
  _elementValueDidChange: function() {
    Ember.set(this, 'value', this.$().getCode());
  },
  didInsertElement: function() {
    this.$().redactor();
    this._updateElementValue();
  }
});
于 2013-02-06T07:54:16.913 に答える