【问题标题】:ember js trigger actions on my routeember js在我的路线上触发动作
【发布时间】:2018-01-07 23:42:45
【问题描述】:

当前网址:http://localhost:4200/bands

router.js:

Router.map(function() {
    this.route('bands', function(){
        this.route('band', {path: ':slug'}, function(){
          this.route('songs');
          this.route('albums');
      });
    });
});

app/routes/bands.js

export default Route.extend({
    actions: {
      createBand: function(){
         this.get('controller').set('name', '');
      }
    }
});

app/templates/bands.hbs

{{input type="text" class="new-band" placeholder="New Band" value=name}}
<button class="btn btn-primary btn-sm new-band-button" {{action 'createBand'}}>Add</button>

好像无法触发 createBand() 函数。 我错过了什么吗?

【问题讨论】:

标签: javascript ember.js routes action


【解决方案1】:

.hbs 文件中给出的操作将在controller 中实现,但您已在route 中实现它们。 当在controller 中找不到该操作时,它会转到其route

更新了JS Bin

它应该可以工作。

【讨论】:

    【解决方案2】:

    我最终做了以下工作:

    onclick={{action "createBand"}}
    

    【讨论】:

    • 你需要在bands.js控制器的action hash中定义action createBand,然后你需要调用this.send('createBandInRoutefunction')你可以参考my answer
    猜你喜欢
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多