简体   繁体   English

Emberjs-使用专注于自身的Views / Handlebar Helpers创建按钮

[英]Emberjs - Creating a button using Views/Handlebar Helpers that focuses on itself

I have a Handlebars helper view that uses Em.Button(I know it's deprecated) to make a Deactivate Button that focuses on itself when the button appears. 我有一个使用Em.Button(我知道它已被弃用)的Handlebars助手视图,以制作一个在按钮出现时专注于自身的Deactivate Button。 Clicking the button triggers the 'delete' action and focus-out uses an action to 'cancelDelete' 单击该按钮将触发“删除”操作,而焦点对准则会使用一个操作来“取消删除”

The problem is that handlebar helpers do not have a closing {{ / }} handlebar, preventing me from putting an text inside of the button, the button just ends up being an empty shell. 问题是车把帮手没有闭合的{{/}}车把,这使我无法在按钮内放置文本,该按钮最终只是一个空壳。 How do I give this button a text value? 如何为该按钮提供文本值? OR Is there an easier way of making this button without Em.Button? 或者有没有Em.Button的更简单的方法来制作此按钮?

The green check will go to the answer that makes this button work. 绿色复选标记将转到使该按钮起作用的答案。

The handlebar helper looks like this 车把帮手看起来像这样

{{delete-recordCategory class="" value=recordCategory focus-out="cancelDeactivate" insert-newline="cancelDeactivate"}}

In the view is where i added the focus and the click 'deactivate' action using 在视图中,我使用以下命令添加了焦点并单击了“停用”操作

VpcYeoman.DeleteRecordCategoryView = Em.Button.extend(Ember.ViewTargetActionSupport, {
  click: function() {
    this.triggerAction({
      action: 'deactivateCategoryNow'
    }); // Sends the `save` action, along with the current context
        // to the current controller
  },
  didInsertElement: function() {
    this.$().focus();
  }
});

Ember.Handlebars.helper('delete-recordCategory', VpcYeoman.DeleteRecordCategoryView);

The ember site suggested Ember.ViewTargetActionSupport as the way to add actions to this view. 余烬站点建议使用Ember.ViewTargetActionSupport作为向此视图添加操作的方式。

Ember v. 1.0 灰烬v。1.0

Ember.Button isn't just deprecated, it's been completely removed from newer versions. Ember.Button不仅被弃用,而且已从较新版本中完全删除。 Definitely not something you want to keep around. 绝对不是您想要保留的东西。 Try writing your own. 尝试自己编写。 Here's a quick example of a component that might do what you want: 这是一个可能会做您想做的组件的快速示例:

App.FocusButtonComponent = Ember.Component.extend({
    didInsertElement: function() {
        Em.run.later(function() {
            this.$('button').focus();
        }.bind(this), 1);
    },

    actions: {
        click: function() {
            this.sendAction('click');
        }
    }
});

focus_button.hbs focus_button.hbs

<button {{action 'click' on='click' bubbles=false}}>
    {{yield}}
</button>

Then, you could use it like this: 然后,您可以像这样使用它:

{{focus-button click='deactivateCategoryNow'}}
    Text Goes Here. Could be anything. <strong>Anything.</strong>
{{/focus-button}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM