除了点击之外的Ember事件 [英] Ember events other than click

查看:84
本文介绍了除了点击之外的Ember事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:在这里找到答案:使用Ember.js,在渲染视图后如何运行一些JS?

found the answer here: Using Ember.js, how do I run some JS after a view is rendered?

在mapView

didInsertElement: function() {
  this._super();
  map_initialize();
},

***********原始帖子** **************

*********** original post ****************

我很喜欢js,正在尝试ember.js。

I'm pretty new to js and am trying ember.js.

我试图使用google maps api来显示地图。通常你应该使用

I am trying to use the google maps api to show a map. Normally you should initialize the map with

<body onload="map_initialize()">

但是,将会收到地图的地图是Ember视图模板的一部分,它还没有在DOM中调用函数时。

but as the map div that will receive the map is part of an ember view template it is not yet in the DOM when the function is called.

console.log(document.getElementById("map_canvas"));

返回false

然后我放置我的地图视图中的初始化函数,以便可以从绑定到地图div本身的事件调用它。这样就可以在加载div之前调用map_initialize()。

I then placed the initialization function in my map view so that could call it from an event tied to the map div itself. This way it is impossible to call map_initialize() before the div is loaded.

<script type="text/x-handlebars" data-template-name="map" >

<div id="map_canvas" style="width:100%; height:100%" {{action "map_initialize" on="click"}}></div>

</script>

这样做完美。当页面加载时,我可以点击地图div,然后加载地图。

this works perfectly. When the page loads, I can click on the map div and then the map is loaded.

我的问题是,如何让这个事件在div被添加到DOM

My question is, how can I get this event to be called automatically after the div is added to the DOM

<div id="map_canvas" style="width:100%; height:100%" onload="initialize()"></div>

没有任何效果(map_initialize()函数未调用)

has no effect (the map_initialize() function is not called).

我也试图通过ember与

I have also tried to do this via ember with

<div id="map_canvas" style="width:100%; height:100%" {{action "map_initialize" on="load"}}></div>

但这样做也不做任何事。

but this also does nothing.

什么是正确的事件名称?

What is the correct event name?

谢谢

推荐答案

覆盖 didInsertElement()在视图(并可能调用 this._super()里面,调用刚刚阴影的函数)。

Override didInsertElement() on the view (and probably call this._super() inside, calling the function you just shadowed).

您还可以监听DOM的更改,例如 DOMNodeInserted DOMSubtreeModified ,但这将包括任何更改

You can also listen to changes to the DOM, such as DOMNodeInserted or DOMSubtreeModified, but that would include any change

这篇关于除了点击之外的Ember事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆