How do I run client-side code after a new collection item has been added to a Meteor view?

后端 未结 2 878
感情败类
感情败类 2021-01-23 13:26

In my template, I call a server-side method to add an item to a collection. This collection is displayed on the page. Once the new item is rendered, I want to focus it for the u

2条回答
  •  无人共我
    2021-01-23 14:01

    One option may be observeChanges? Can you try this?

    in the rendered function do following

    Template.postsAdmin.rendered = function(){
    
       var query = Posts.find({}); //your query
       var handle = query.observeChanges({
           added: function (id, user) {
              //code to set focus???
           }
       });
    }
    

    This code runs whenever there is a new item addeded to minimongo which matches your query.

    Make sure to show the template after you load the data.

    docs link http://docs.meteor.com/#/full/observe_changes

提交回复
热议问题