简体   繁体   English

Safari中的DOM遍历错误-Ember.js

[英]DOM Traversing Error in Safari - Ember.js

I have my template something like this, 我有这样的模板

<ul id="items">
    {{#each items as |item index|}}
       <li>
        <!-- <input type="checkbox" id={{concat "pf" index}} /> -->
        {{input type="checkbox" id=(concat "pf" index)}}
       </li>
    {{/each}}
</ul>

And I have my js something like this, 我有这样的js

import Ember from "ember";

export default Ember.Controller.extend({
  appName: "Ember Twiddle",
  items: [{}],
  init: function() {
    $(document).on("click.somename", function (e) {
      alert($(e.target).parent().length); //should get parent as "li" and length as 1
    });
  }
});

What happening for my project is that, if I click on ember input helper I am not able to get the parentElement using jQuery . 对于我的项目,发生的是,如果我单击ember input helper,则无法使用jQuery获取parentElement But when I changed that input helper to normal <input type="checkbox" /> , I am able to get the parentElement . 但是,当我将输入帮助器更改为普通的<input type="checkbox" /> ,我可以获取parentElement I don't know whether Safari/Ember is using any virtual DOM or something to render its own helpers. 我不知道Safari / Ember是否正在使用任何虚拟DOM或某种方式呈现其自己的帮助器。 This issue is happening only in Safari . 仅在Safari中发生此问题 In Chrome, it is working fine. 在Chrome中,它工作正常。

Unfortunately, I am not able to make a fiddle/plunker as the issue is not able to replicate in them. 不幸的是,我无法摆弄小提琴/ pl子,因为这个问题无法在他们身上复制。 Sorry about that. 对于那个很抱歉。 In my project, I am using ember@2.7.3 . 在我的项目中,我正在使用ember@2.7.3

Any suggestions/help on this issue? 关于这个问题有什么建议/帮助吗?

While I'd recommend trying to find a way to avoid using the jQuery click event in the first place, it sounds like an issue with how the different browsers treat parent . 虽然我建议尝试首先找到一种避免使用jQuery click事件的方法,但这听起来像是不同浏览器如何处理parent I would prefer to use .closest('li').eq(0) to access the first parent that matches the element you are looking for. 我更喜欢使用.closest('li').eq(0)访问与您要查找的元素匹配的第一个父对象。

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

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