Ember生成动作或jquery onclick [英] Ember generated action or jquery onclick

查看:105
本文介绍了Ember生成动作或jquery onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ember应用程序工作正常。但是用户的交互做了一些如下面的DOM插入...

  $(。test).append(< a {{action getData}}>获取数据< / a>); 

问题是Ember似乎不认识到一个动作getData已被添加到DOM 。当我单击元素时,没有发生任何事情。有任何想法吗?



我想要做的另一种方法是:

  //创建元素
$(。test).append(< a id =idnum> Get Data< / a>);

// make click listener
$('#idnum')。click(function(){
console.log(get data);
}

我的问题是我应该将代码放在组件中,以便它可以在点击事件谢谢。

解决方案

你应该以Ember的方式执行它。尝试handlebars {{#if}}助手来动态渲染元素。

  {{#if canGetData}} 
< a {{actiongetData}}>获取数据< / a>
{{/ if}}

这里您可以设置值根据用户操作,canGetData在控制器中为true。


I have an ember application which works fine. But user's interaction does some DOM insertion like below...

$(.test).append(<a {{action "getData"}}>Get Data</a>);

The problem is that Ember seems do not recognize that an action "getData" has been added to the DOM. Nothing is happening when I click the element. Any thoughts on this?

Another way I am trying to do is:

 //create the element
 $(.test).append(<a id="idnum">Get Data</a>);

 //make click listener
 $('#idnum').click(function(){
 console.log("get data");
}

my question is where should i place the code inside the component so the it can listen on the click event. Thanks.

解决方案

You should do it in Ember way. Try handlebars {{#if}} helper to render an element dynamically.

{{#if canGetData}}
<a {{action "getData"}}>Get Data</a>
{{/if}}

Here you can set the value of the canGetData to true in the controller based on the users action.

这篇关于Ember生成动作或jquery onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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