Dynamic button id some_String+button_value with ember view

143 Views Asked by At

Hi at the moment I create some buttons dynamically with ember view like this:

{{#each item in content._data.cpu_choices}}
                            {{#view App.CPUSelButView id=item value=item name="cpu_button" disabled=cpu_Not_Allow}}{{item}}x{{/view}}
                        {{/each

}

My view is

// View used for CPU selection buttons
App.CPUSelButView = Ember.View.extend({
    tagName: 'button',
    // class names, :emberbutton for CSS style
    classNameBindings: [':emberbutton', ':btn', ':btn-primary', ':btn-xs'],
    // html attributes, custom (e.g. name, value) should be defined here
    attributeBindings: ['disabled', 'name', 'value'],
    // on click
    click: function () {
    // for this controller, trigger the CPU_selection and send the value
        this.get('controller').send('cpu_selection', this.get('value'));
    }

});

What i want now is to change the id from item(which is dynamic) to some_stirng_item use a prefix to the current id actually is there a way to do this.

I need id to search elements by id.

1

There are 1 best solutions below

0
On BEST ANSWER

I solve my problem by adding this into my view:

// Set this view's id 
    init: function() {
        this.set('elementId', "cpu_" + this.get('value'));
        return this._super();
    },