javascript - 为什么这些 Ember.js View 事件没有被触发?

标签 javascript ember.js

当我的 View 变得可见时,我尝试执行某些操作,但未调用 becameVisible 事件回调。

这是我的观点:

App.LessonView = Ember.View.extend({
    click: function() {
        console.log("click");
    },

    becameVisible: function() {
        console.log("becameVisible");
    },

    willClearRender: function() {
        console.log("willClearRender");
    }
});

当我单击 View 中的任何元素时,会触发 click 事件,但不会触发 becameVisiblewillClearRender 事件。

有什么我不明白的地方吗?

最佳答案

didInsertElement 当 Ember 将 View dom 放入页面时触发。 当 ember 从页面中删除 dom 时,willDestroyElement 将触发。

App.LessonView = Ember.View.extend({
    click: function() {
        console.log("click");
    },

    didInsertElement: function() {
        console.log("didInsertElement");
    },

    willDestroyElement: function() {
        console.log("willDestroyElement");
    }
});

使用didInsertElement时应该注意的一些事情 1. 当支持 View 的模型发生更改时,Ember 将更新当前 View 中的绑定(bind),因此 Ember 不必重新插入 View ,并且 didInsertElement 也不会触发。 2. 如果您在 didInsertElement 上设置事件处理程序(例如引导菜单事件),则需要在 willDestroyElement 事件中关闭该绑定(bind)。

关于javascript - 为什么这些 Ember.js View 事件没有被触发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23094975/

相关文章:

jquery - ember,使用 jquery 更新表单值

ember.js - 如何使用尖括号定义输入?

javascript - Ember 过渡和渲染完成事件

javascript - ES6/TS/Angular2 将 JSON 解析为 Date

javascript - ng-repeat angular js 的问题

java - 将参数传递给 url

javascript - Ember.js 过渡渲染错误或错误的路由

ember.js - Ember : deactivate not called when transitioning from one route to another

javascript - 在发出 API 请求时,将函数错误从 React 中的父组件传播到子组件

javascript - readline rl.write 如何工作?