Search code examples
javascriptmeteormeteor-blaze

Pass object back to event Meteor?


I'm trying to pass a object back to a event in Blaze I have my Blaze template defined like so:

<template name="plugins_list">
<h2>Import area</h2>
<button class="importjars">Import from FS</button>
{{plugins.ancientgatesreloaded.author}}
<dl>
    {{#each plugin in plugins}}
        <dt><button class="add_plugin_to_store" data="{{plugin}}">+</button> <a href="{{plugin.website}}" target="_blank">{{plugin.name}}</a> ( {{plugin.version}} ) </dt>
        <dd>Author: {{plugin.author}}</dd>
    {{/each}}
</dl>
<h2>Data Store</h2>
<dl>
    {{#each plugin in masterplugins}}
        <dt><a href="{{plugin.website}}" target="_blank">{{plugin.name}}</a> ( {{plugin.version}} )</dt>
        <dd>Author: {{plugin.author}}</dd>
    {{/each}}
</dl>

And my events like so:

    Template.plugins_list.events({
    'click button.importjars': function () {
        Meteor.call("getMCPlugins", function(error, response){
            var plugins = response;
            Session.set('plugins', plugins);
            console.log(plugins);
        });
    },
    'click button.add_plugin_to_store': function (event) {
        console.log(event);
    }
});

how do I pass my "plugin" object back to the ' 'click button.add_plugin_to_store':' event in my helper from the each inside of blaze upon clicking the + ?

Kind regards Chris


Solution

  • Use Blaze.getData([elementOfView]).

    Returns the current data context, or the data context that was used when rendering a particular DOM element or View from a Meteor template.

    This will print the object to the console log.

    'click button.add_plugin_to_store': function (event) {
        console.log(Blaze.getData(event.target));
    }