Ember生成动作或jquery onclick [英] Ember generated action or jquery onclick
问题描述
$(。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屋!