Why is no posible change value of Ex: Template.instance().data


This´s a newbie question.
Why I can´t set data context to where ever object?


'dblclick tbody > tr': function (event) {
    // Current rowData
    var dataTable = $(event.target).closest('table').DataTable();
    var rowData = dataTable.row(event.currentTarget).data();

    Template.instance().data = rowData;
    console.log('[Template.instance().data]: ', Template.instance().data);

On console instance data remain the same.


Template.instance().data is a convenient way of getting to the data context of the current instance of the template within helpers, event handlers, callbacks and autoruns. From the documentation this is read only.


There is a pattern that allows to use Template.instance() to communicate between events and helpers, though (here is an old meteorpad about this)

Basically you add a (reactive) variable to the template during creation, and then access that variable in your event handlers and helpers

Template.instance().data is readonly, however, just as @robfallows said.


Thanks Rob.
I use this code.

DataTableExtra.events = {
    // Here we fired a custom event(dblclickrow) for past current rowData to template.rowData
    'dblclick tbody > tr': function (event, template) {
        // Current rowData
        var dataTable = $(event.target).closest('table').DataTable();
        var rowData = dataTable.row(event.currentTarget).data();
        template.rowData = rowData;

DataTableExtra.events is a shared event handler

    //dblclickrow a custom event on datatable-extra package
    'dblclickrow tbody > tr': function(event, template) {
        // code here
       console.log('[rowData dblclickrow]: ', template.rowData);


thanks @jamgold I know and use that pattern but I was trying to set data context on template instances who has useless this.
I ´m a newbie trying to behave like a “oldbie” :smile: