2013-11-23 39 views
1

我有一个把手模板是这样的:如何显示元素时另一个元素集中在灰烬/把手

<input> 
<button>save</button> 

这将会是非常简单的实现jQuery的预期的效果,并在Ang-ng-show指令可能会完成这项工作。

输入焦点时显示按钮的Ember方式是什么?

目前我玩弄#unless的假设,计算属性会做的伎俩,类似于Knockout计算。

App.DashboardView = App.BaseView.extend({ 
    notesFocused: function() { 
     this.$('#notes').is(':focus'); 
    } 
}); 

和:

{{#unless notesFocused}} 
    <button>save</button> 
{{/unless}} 

这不是工作,但是我怀疑我在正确的轨道上。我会很感激任何指针。

回答

3

您可以使用focus-infocus-out来自Ember.TextField,将focusIn和focusOut事件转移到控制器或路由。并保持状态的变量:

{{input type="text" focus-in="notesFocusIn" focus-out="notesFocusOut"}}  
{{#unless notesFocused}} 
    <button>save</button> 
{{/unless}} 

控制器

App.DashboardController = Ember.Controller.extend({ 
    notesFocused: false, 
    actions: { 
     notesFocusIn: function() { 
      this.set('notesFocused', true); 
     }, 
     notesFocusOut: function() { 
      this.set('notesFocused', false); 
     } 
    } 
}); 

在操作中查看http://jsfiddle.net/marciojunior/KN4dk/

+0

非常整洁,谢谢。 – bcmcfc

相关问题