lundi 30 janvier 2017

Buttons: Change value by ID in Ember.js

I‘m trying to have a set of buttons in an <button>...</button> block, and to get the target values by an ID of the model ...

Let’s say there is a controller with model and action:

export default Ember.Component.extend({

    Texts: [
        {id: "1", name: "One", sample: "Hello!"},
        {id: "2", name: "Two", sample: "Hello! Hello!"},
        {id: "3", name: "Three", sample: "Hello! Hello! Hello! "},
    ],

    theText: "Test",

    actions: {
        setText: function(id) {
            var theText= this.get('Texts.sample', id);
            this.set('theText');
            console.log(theText);
        }

});

and this in the template:


    <button ></button>


<span></span>

... this is my idea, but all I get is an undefined ...




Aucun commentaire:

Enregistrer un commentaire