EmberJS 模板停止事件传播
2018-01-03 18:58 更新
描述
您还可以通过禁用传播到父节点来停止传播。参数bubbles = false将阻止浏览器传播事件。它确保按钮链接不被点击。
语句
{{#link-to 'link text'}} <button {{action 'actionName' bubbles=false}}>ButtonName</button> {{/link-to}}
例子
<!DOCTYPE html> <html> <head> <title>Emberjs Stopping Event Propagation</title> <!-- CDN's --> <script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/3.0.1/handlebars.min.js"></script> <script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.10.0/ember.min.js"></script> <script src="https://builds.emberjs.com/tags/v1.10.0-beta.3/ember-template-compiler.js"></script> <script src="https://builds.emberjs.com/release/ember.debug.js"></script> <script src="https://builds.emberjs.com/beta/ember-data.js"></script> </head> <body> <script type="text/x-handlebars"> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="index"> <div {{action 'User'}}> <h2> Link 1 </h2><br/> <!-- disabling the multiple calls for link 1 by making bubble=false --> <span {{action 'User1' bubbles=false}}> <h2> Link 2 </h2> </span> </div> </script> <script type="text/javascript"> App = Ember.Application.create(); App.IndexRoute = Ember.Route.extend({ actions: { //creating an action event User: function () { document.write('Welcome to Tutorialspoint'); }, //creating an action event User1: function () { document.write('Hello'); } } }); </script> </body> </html>
输出
让我们执行以下步骤,看看上面的代码如何工作:
将上面的代码保存在temp_act_event_prop.html文件中
在浏览器中打开此HTML文件。
以上内容是否对您有帮助:
更多建议: