2015-11-25 83 views
0
I am using ember view, once the page loads i want to scroll down to the page.In view didInsertElement will call and make the page load to scroll down, here is my code 

App.MessagesView = Ember.View.extend({ 
    didInsertElement: function() { 
    this._super(); 
    var $target = $('.chat-area .chat-list') 
    , height = 0; 
    if ($target) { 
     $target.each(function(i, items_list) { 
      $(items_list).find('li').each(function() { 
       console.log($(this).height()); 
       height = height + parseInt($(this).height()); 
      }); 
     }); 
     $target.animate({ scrollTop: height}); 
    } 
} 

更新所述屬性如果新其他消息被裝載之後但是,一旦在控制裝置,因爲該視圖已經被加載,所述滾動條不滾動至page.for其他消息。新的消息更新到計算的屬性,我想在DOM消息更新並調用scrolldown代碼後調用。如何滾動到DOWN使用餘燼

App.MessagesController = Ember.ArrayController.extend({ 
    newmsgsCaptured: function(uuid) { 
     this.setProperties({ 
       'newSelectedMessages': response, 

      }); 

      var $target = $('.chat-area .chat-list') 
      , height = 0; 
      if ($target) { 
       $target.each(function(i, items_list) { 
        $(items_list).find('li').each(function() { 
         console.log($(this).height()); 
         height = height + parseInt($(this).height()); 
        }); 
       }); 
       console.log(height); 
       $target.animate({ scrollBottom: height}); 
      } 

    } 
}); 

after calling newmsgsCaptured 'acction', the property is updated with new data and the scrolled down is not working. 
+0

看看觀察者http://guides.emberjs.com/v2.0.0/object-模型/觀察員/ –

回答

1

您將需要建立在任何地方都存儲在消息的觀察者:

messagesUpdated: function() { 
    //scroll action here 
}.observes('messagesArray'), 

這將觸發功能每當「messagesArray」變化

0

其實我已經做到了查看如下

didInsertElement: function() { 
    Ember.run.schedule("afterRender", this, function() { 
     if (this.get('controller.isScrollDown')) { 
      this.send("scrollDown"); 
     } 
    }); 
}.observes('controller.vehicleSelectedMessages'),