如何使用 Ember 更新属性后滚动到 DOWN

how to scrolled to DOWN after updating the properties using ember

本文关键字:滚动 DOWN 属性 何使用 Ember 更新      更新时间:2023-09-26
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});
    }
}

但是一旦进入控制器,如果加载了新的其他消息,因为视图已经加载,滚动条不会向下滚动到页面。 对于另一条消息,新消息将更新为计算属性,我想在更新 DOM 消息后调用并调用向下滚动代码。

  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.

您需要在消息的存储位置设置观察器:

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

这将在"消息数组"更改时触发该函数

实际上我已经完成了如下视图

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