Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 202
vimes1984 Avatar asked Feb 03 '26 19:02

vimes1984


1 Answers

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));
}
like image 87
JeremyK Avatar answered Feb 06 '26 12:02

JeremyK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!