javascript - 错误 : Failed to execute 'insertBefore' on 'Node'

标签 javascript meteor meteor-blaze meteoric

我尝试插入 <div> {{#each}} 周围的容器,但效果不佳。这也很奇怪,因为它适用于 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}}

最佳答案

试试这个,让我知道:

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

如果可行,我会做出解释

关于javascript - 错误 : Failed to execute 'insertBefore' on 'Node' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35017820/

相关文章:

javascript - 如何从 iframe 将元素附加到父主体?

javascript - 浏览器原生滚动功能 : how to check compatibility

javascript - 制作 meteor 重新渲染 "unchanged"字段

javascript - React 'component' 参数缺失错误?

javascript - 如何让元素根据滚动位置逐步变换

javascript - 包含部分内容时可以传递 php 变量吗?

mongodb - Meteor 对集合有独特的查询吗?

javascript - JQuery 与变量一起使用时不添加类

javascript - 在 MongoDB 中插入/更新插入嵌套文档

javascript - IronRouter 获取布局中的数据