【问题标题】:Get current element on {{action}} in emberJS在 emberJS 中获取 {{action}} 上的当前元素
【发布时间】:2014-10-03 23:20:33
【问题描述】:

谁能帮我在 emberJS {{action}} 上获取元素?

例如

// application.hbs
<a href="#" {{action 'displayLinks'}}>Get me</a>

// app.js
App.IndexRoute = Ember.Route.extend({
     actions: {
         displayLinks: function() { 
            // returns an object with, no element properties
            console.log(this); 
         }
     }
});

【问题讨论】:

    标签: ember.js routes action


    【解决方案1】:
    // application.hbs
    <a href="#" id="elementId" {{action 'displayLinks' 'elementId'}}>Get me</a>
    
    // app.js
    App.ApplicationRoute = Ember.Route.extend({
         actions: {
             displayLinks: function(id) { 
                 console.log($("#" + id)[0]);
             }
         }
    });
    

    【讨论】:

    • 我明白了。所以我只需要将 id 作为参数传递给操作。这是否可以从那里触发一些路线?
    • 是的。但是你想做什么?如果您想链接到另一条路线,只需使用 link-to 助手。
    猜你喜欢
    • 2012-08-04
    • 2017-12-29
    • 2013-03-01
    • 2013-09-10
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 2012-06-20
    • 2016-11-18
    相关资源
    最近更新 更多