user1259552
user1259552

Reputation: 141

Event delegation issue in Sencha / ExtJS

I'm trying to use an event delegation to add to the store the label of the checkbox I'm checking in Sencha.

How could I pass the label of the checkbox as a parameter? Am I doing well the delegation? I have an error like 'Unexpected token'.

I really have to put the function apart because I want to write like 30 checkboxes, and everyone with the same listener when is checked.

Thank you so much in advance.

//this chekbox code
{
    xtype: 'checkboxfield',
    label: 'Noir',
    listeners: {
        check: anadir(label)
    }
}

//This check function code
anadir: function(label) {
    console.log("Añadiendo...");
    var index = storemisOpciones.getCount() - 1;
    console.log("Indice: " + index);
    storemisOpciones.add({
        option: label
    });
    console.log(label + " se ha marcado");
    index = storemisOpciones.getCount() - 1;
    console.log("Indice: " + index);
    console.log(storemisOpciones.getAt(index));
    storemisOpciones.sync();
}

Upvotes: 2

Views: 328

Answers (1)

sha
sha

Reputation: 17860

Try defining listeners as (I don't think there check event in ExtJs):

listeners: {
    change: function(control) {
         anadir(control);
    }
}

Upvotes: 1

Related Questions