【问题标题】:Error: Failed to execute 'insertBefore' on 'Node'错误:无法在“节点”上执行“插入之前”
【发布时间】:2016-05-03 06:01:30
【问题描述】:

我尝试在 {{#each}} 周围插入 <div> 容器,但效果不佳。这也很奇怪,因为它适用于 2 个普通帖子列表页面,但不适用于按距离对它们进行排序的第 3 个。

更新: 我注意到在我将模板 JS 从template.name.onRendered 更改为onCreated 之后,排序页面就可以工作了。但是,它仅在您从以前的帖子列表页面而不是从个人资料页面进入时才有效。

错误页面的唯一共同点是那些页面使用 publishComposite 进行排序。这可能是因为 publishComposite 有子父关系的问题吗?

错误信息

Exception in queued task: Error: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.
    at Error (native)
    at Object.container._uihooks.insertElement (http://localhost:3000/packages/meteoric_ionic.js?e45c114e85716d9fad8bac1cd7904ae2700bc963:5750:19)
    at DOMRange._insertNodeWithHooks (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:383:21)
    at Function.Blaze._DOMRange._insertNodeWithHooks (http://localhost:3000/packages/peerlibrary_blaze-components.js?4eddb4e3f0f660190548347e680d109a51a7050f:2377:10)
    at Function.DOMRange._insert (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:354:16)
    at DOMRange.attach (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:431:16)
    at Blaze._DOMRange.attach (http://localhost:3000/packages/peerlibrary_blaze-components.js?4eddb4e3f0f660190548347e680d109a51a7050f:2437:33)
    at Function.DOMRange._insert (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:349:7)
    at DOMRange.attach (http://localhost:3000/packages/blaze.js?695c7798b7f4eebed3f8ce0cbb17c21748ff8ba8:431:16)
    at Blaze._DOMRange.attach (http://localhost:3000/packages/peerlibrary_blaze-components.js?4eddb4e3f0f660190548347e680d109a51a7050f:2437:33)

第 19 行引用的 meteoric_ionic js 文件

container._uihooks = {                                                                                               
    insertElement: function(node, next) {                                                                              
      var $node = $(node);                                                                                             
      if (!template.transition || !$node.hasClass('view') || IonNavigation.skipTransitions) {                         
        container.insertBefore(node, next);  //line 19                                                                          
        return;                                                                                                        
      }  

相关的html

  {{#ionView}}
    {{#ionContent}}
        {{#ionList}}
            <div>
              {{#each shops}}
                    {{> shopItem}}
              {{/each}}
            </div>
        {{/ionList}}
    {{/ionContent}}
  {{/ionView}}

【问题讨论】:

  • 有一个similar problem in another question。您可能想尝试一下。
  • 我做到了,它消除了一些错误,但主要问题仍未解决。我在文章开头提到过。
  • This 可能会对您有所帮助。
  • @Hans 同样,没有解决问题。我用谷歌搜索了这个问题,之前在页面上。我想知道这是什么问题!
  • 您需要在此处发布更多代码。结构本身没有问题,但是模板中的 javascript 正在对 dom 进行一些动态插入,这会导致问题。从您的每个模板中发布您的 onRendered/onCreated 代码,我们将能够提供帮助。

标签: javascript meteor meteor-blaze meteoric


【解决方案1】:

我通过将 cdk 从版本 9 更新到 11 来修复它。

我的案例:将 mat-card(cdkDrag) 嵌入 mat-grid-list(cdkDropListGroup)/mat-grid-tile

提醒'Node'上执行'insertBefore'失败:要插入新节点的节点不是该节点的子节点。'

【讨论】:

    【解决方案2】:

    试试这个并告诉我:

    Template.nearShops.onCreated(function () {  
      var self = this;
      self.autorun(function () {
        self.interval = Meteor.setInterval(function(){
          var currentLocation = Geolocation.latLng() || '';
          if(currentLocation) {
            Session.set('lat', currentLocation.lat);
            Session.set('lng', currentLocation.lng);
          }
        }, 2000);   
      });
      self.autorun(function(){  
        if(Session.get('lat')) {
          self.subscribe( "nearShops", Session.get('lng'), Session.get('lat') );
        }
      });
    });
    

    如果这个工作我会做解释

    【讨论】:

    • 我希望赞成票是个好兆头,但它仍然不适合我。关于我应该调整什么的任何其他建议?这个想法只是在我单击此选项卡时获取当前位置。
    • @Thinkerer 你能发布这个文件吗:meteoric_ionic.js?e45c114e85716d9fad8bac1cd7904ae2700bc963:5750:19 我确实从源头搜索但找不到。看来您正在使用折旧包。
    • 我怀疑这与包装有关。我建议你打开一个问题
    • 我将为此打开一个问题。会有任何解决方法吗?由于该错误会阻止页面加载。
    • 我认为只要提到这个问题就足够了。您应该从包维护者那里获得更多见解。
    猜你喜欢
    • 2023-04-01
    • 2021-07-30
    • 2021-02-19
    • 2021-03-28
    • 2014-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多