当使用DOM更新完成垃圾时执行某些操作

编程入门 行业动态 更新时间:2024-10-20 13:32:04
本文介绍了当使用DOM更新完成垃圾时执行某些操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经尝试使用来自操作绑定的函数的回调函数在执行回调时,DOM不会被更新。

我直接在模型上尝试了一个观察者,当执行观察者时,DOM不会更新。 >

我已经尝试了一个观察者的绑定,当执行观察者时,DOM不会被更新。

eg

App.view = Ember.View.extend({ modelBinding:'App.model', modelChanged :function(){ window.scrollTo(0,document.body.scrollHeight); } .observes('model'), getMore:function(event){ App.set('model',somethingnew); } });

当我点燃gotMore时,我更新了模型,当模型更新并且更改已经呈现,我想向下滚动。

在我尝试过的任何方式中,我都能够获得新的scrollHeight。在这些事件之后,它设置了几ms。

这是一个jsFiddle的例子: jsfiddle/kcjzw/15/

解决方案

正确的方法是记录在这里:

emberjs/api/classes/Ember.run.html#method_next

modelChanged: function(){ Ember.run.scheduleOnce('afterRender',this,function(){ window.scrollTo(0,document.body.scrollHeight); $('body' ).append('New scroll height:'+ document.body.scrollHeight); }); } .observes('content')

I want to do stuff when ember bindings have synchronized and the DOM is again up to date.

I have tried with a callback from the function that manipulates the binded model, DOM is not updated when callback is executed.

I have tried with an observer directly on the model, DOM is not updated when the observer is executed.

I have tried with an observer on the binding, DOM is not updated when the observer is executed.

e.g.

App.view = Ember.View.extend({ modelBinding: 'App.model', modelChanged : function() { window.scrollTo(0, document.body.scrollHeight); }.observes('model'), getMore: function(event) { App.set('model', "somethingnew"); } });

When I fire the "gotMore", I update the model, and when the model is updated and its changes have been rendered I want to scroll down.

In none of the ways I've tried have I been able to get the new scrollHeight. It is set a few ms after these events.

Here's an example on jsFiddle: jsfiddle/kcjzw/15/

解决方案

The correct way to do this is documented here:

emberjs/api/classes/Ember.run.html#method_next

modelChanged : function() { Ember.run.scheduleOnce('afterRender', this, function() { window.scrollTo(0, document.body.scrollHeight); $('body').append('New scroll height: '+document.body.scrollHeight); }); }.observes('content')

更多推荐

当使用DOM更新完成垃圾时执行某些操作

本文发布于:2023-11-11 23:22:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579821.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:垃圾   操作   DOM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!