mardi 16 juin 2015

Sync Meteor checkbox state with database

I have a checkbox in my application and what i am trying to do is store the state of checkbox i.e if its checked or not. Once user checks the checkbox its store it in to database and when next time he visit the page it should be checked.

I am trying to use session and it works across different pages on same application but once i reload the page its gone. I guess session works for temporary data. What should be use for permanent data?

HTML

<template name="test">
    <input type="checkbox" id="check" checked="{{Checked}}"> 
</template>

JS

Template.Test.events({
    'click #check':function(e){
        Session.set('Checked', e.target.checked);
    }
})

Template.Test.helpers({
    Checked: function(){
        return Session.get("Checked");
    }
})




Aucun commentaire:

Enregistrer un commentaire