LoginSignup
0
0

More than 5 years have passed since last update.

Backbone.Viewでやりがちなミス

Last updated at Posted at 2013-09-14

positionやoffsetを取得するときに上手く動作しないことがあります。
大抵はthis.$elがまだhtml本文に挿入されていないというものです。

わかっていても定期的にやってしまいます。

うっかり
class View extends Backbone.View{

    constructor(options?){
        super(options);
        //この位置ではだめ
        this.render();
        $('body').append(this.$el);
    }
    render(){
        //this.$elが挿入前だと取得したい値が正しくとれない
        var position = this.$el.position();
        return this;
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0