Meteor.js - temporarily prevent a template from re-rendering (disable reactivity)

前端 未结 2 1114
太阳男子
太阳男子 2021-01-01 06:06

I have a page in my app with a list of Projects the user is working on.

When they want to add a new project, I show a modal form to get the name of the project.

相关标签:
2条回答
  • 2021-01-01 06:28

    You can put your html containing this into a {{#constant}} block. Docs on constant

    e.g

    {{#constant}}
        {{#each ...}}
        ....
        {{/each}}
    {{/constant}}
    

    Another option is to disable reactivity in your template helper e.g if you have

    Template.home.mydata = function() { return MyCollection.find() }
    

    change this to use reactive:false as an option

    Template.home.mydata = function() { return MyCollection.find({}, {reactive:false}) }
    

    This way the initial changes are shown but any updates aren't used so there wouldn't be a re-render.

    0 讨论(0)
  • 2021-01-01 06:33

    I have found that using cancel inside the event handler after the call to the methods cancels the chain of reactivity.

    Template.questionTeaser.events({
      "click .vote_add": function(event, template){
        Meteor.call('vote_add', this._id, this.session)
    
        // This cancels the chain of reactivity.
        return false
      },
    })
    

    I use it for the following use case:

    Users sees a list of questions sorted by votes User can upvote After upvote the list gets rerendered/sorted BUT with a countdown in the rightside of the page so the user knows he cant click for a second.

    0 讨论(0)
提交回复
热议问题