最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error: Failed to execute 'insertBefore' on 'Node' - Stack Overflow

programmeradmin4浏览0评论

I tried to insert <div> containers around the {{#each}} but it didn't work as well. Its also odd because it works for 2 normal posts list pages, but not for the 3rd one which sorts them by distance.

Updates: I noticed that after i change the template JS from template.name.onRendered to onCreated, the sorting page works. However it works only if you go from a previous post list page and not from the profile page.

The only mon ground of the error pages is those pages use publishComposite for sorting. Could that be the issue since publishComposite has a child to parent relationship?

The error message

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-ponents.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-ponents.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-ponents.js?4eddb4e3f0f660190548347e680d109a51a7050f:2437:33)

The meteoric_ionic js file referred to line 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;                                                                                                        
      }  

The relevant html

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

I tried to insert <div> containers around the {{#each}} but it didn't work as well. Its also odd because it works for 2 normal posts list pages, but not for the 3rd one which sorts them by distance.

Updates: I noticed that after i change the template JS from template.name.onRendered to onCreated, the sorting page works. However it works only if you go from a previous post list page and not from the profile page.

The only mon ground of the error pages is those pages use publishComposite for sorting. Could that be the issue since publishComposite has a child to parent relationship?

The error message

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-ponents.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-ponents.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-ponents.js?4eddb4e3f0f660190548347e680d109a51a7050f:2437:33)

The meteoric_ionic js file referred to line 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;                                                                                                        
      }  

The relevant html

  {{#ionView}}
    {{#ionContent}}
        {{#ionList}}
            <div>
              {{#each shops}}
                    {{> shopItem}}
              {{/each}}
            </div>
        {{/ionList}}
    {{/ionContent}}
  {{/ionView}}
Share Improve this question edited Apr 15, 2016 at 15:08 Thinkerer asked Jan 26, 2016 at 15:42 ThinkererThinkerer 1,6266 gold badges23 silver badges43 bronze badges 5
  • There's a similar problem in another question. You might want to give it a try. – user4454229 Commented Jan 26, 2016 at 15:51
  • I did, it removed some errors but main problem is unresolved. I mentioned it at the start of my post. – Thinkerer Commented Jan 26, 2016 at 16:11
  • This might help you. – Hans Commented Jan 26, 2016 at 16:20
  • @Hans Same, didnt solve the problem. I googled the issue and was previously at the page. I wonder whats the issue! – Thinkerer Commented Jan 27, 2016 at 15:00
  • 2 You will need to post more code here. There is nothing wrong with the structure itself, but the javascript in your templates is doing some dynamic insertion on the dom and it's causing problems. Post your onRendered/onCreated code from each of your templates and we will be able to help. – Brett McLain Commented Feb 8, 2016 at 16:28
Add a ment  | 

2 Answers 2

Reset to default 4 +25

Try this and let me know:

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

I'll make explaination if this work

I fixed it by updating cdk from release 9 to 11.

My case : embedding of mat-card(cdkDrag) into mat-grid-list(cdkDropListGroup)/mat-grid-tile

Remind 'Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.'

发布评论

评论列表(0)

  1. 暂无评论