简体   繁体   English

如何检测元素外部的点击并通过ember发送事件?

[英]How to detect a click outside an element and send the event by ember?

My problem look like: How do I detect a click outside an element? 我的问题看起来像: 如何检测元素外部的单击?

But I want to use ember.js do this. 但是我想用ember.js做到这一点。 My template code: 我的模板代码:

<td colspan="2" {{action "changeName" on="doubleClick"}}>
  {{#if isEditName}}
    {{input type="text" value=editName class="form-control"}}
  {{else}}
    {{product.name}}
  {{/if}}
</td>

I want to do when I double click the div , show input and I can change name in input . 当我双击div并显示input时我想做,我可以在input更改名称。 I think when I change name and click the body will save the name. 我认为当我更改名称并单击正文时,将保存该名称。 I think is better. 我认为更好。 But I don't know how to set the event in body, when I click the body will hide input and save product.name. 但是我不知道如何在主体中设置事件,当我单击主体时,它将隐藏input并保存product.name。

Thanks. 谢谢。

Add a picture to show the behavior process: 添加图片以显示行为过程:

在此输入图像描述

Not sure what you exactly meant but im guessing you're looking for something like this 不确定您的确切意思,但我猜您正在寻找这样的东西

<td>
  {{#if isEditName}}
    <span {{action "showOrHide" on="doubleClick"}}> {{input type="text" value=product.name class="form-control"}}</span>
  {{else}}
     <span {{action 'showOrHide' on="doubleClick"}}> {{product.name}} </span>
  {{/if}}
</td>


isEditName: false,

actions : {
 showOrHide: function() { 
     this.toggleProperty('isEditName'); 

     if(!this.get('isEditName') { // changed from input to detail view
         this.get('product').save();
     }


 })
}

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

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