错误:无法在'Node'上执行'insertBefore'

时间:2016-01-26 15:42:26

标签: javascript meteor meteor-blaze meteoric

我尝试在{{#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)

meteoric_ionic js文件引用第19行

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}}

2 个答案:

答案 0 :(得分:4)

试试这个让我知道:

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') );
    }
  });
});

如果这项工作我会解释

答案 1 :(得分:2)

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

我的情况:将 mat-card(cdkDrag) 嵌入到 mat-grid-list(cdkDropListGroup)/mat-grid-tile

提醒'无法在'节点'上执行'insertBefore':要在其之前插入新节点的节点不是该节点的子节点。'