Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding attributes to Emberjs component

Tags:

ember.js

i have component like this and want to set some attributes on it:

OlapApp.ItemRowsComponent = Ember.Component.extend({
tagName: 'li',
classNameBindings: ['currentItem.isMeasure:d_measure:d_dimension'],
didInsertElement: function() {
    this.$().draggable({

    });
},
actions: {
    removeItem: function(item) {
        item.deleteRecord();
        item.save();
    },
    didClick: function(item) {
        if (item.get('isMeasure')) {
            item.deleteRecord();
            item.save();
        }
    }
}
});

and i call this component like this :

{{#each item in getRowItem}}
 {{item-rows currentItem=item}}
{{/each}}

item have a id property item.id now i want to set this id to data-id of component to create an element like this :

<li data-id='id of item'>Some text</li>
like image 449
MBehtemam Avatar asked Sep 23 '13 07:09

MBehtemam


3 Answers

Your approach actually works? I would suspect that it shouldn't work that way and should rather be:

OlapApp.ItemRowsComponent = Ember.Component.extend({
  attributeBindings:["data-id"],
  "data-id" : Ember.computed.oneWay("currentItem.id")
  // and the rest of your code ...
});

One little extra remark: Checkout my blog post on how to perform jquery logic correctly: http://mavilein.github.io/javascript/2013/08/01/Ember-JS-After-Render-Event/

like image 151
mavilein Avatar answered Nov 11 '22 02:11

mavilein


You can actually do it without introducing an extra computed property.

attributeBindings:['currentItem.id:data-id']
like image 3
Denzo Avatar answered Nov 11 '22 02:11

Denzo


after searching and trying some way i find that . im using this for solve my problem :

attributeBindings:['getId:data-id'],
getId:function(){return this.get('currentItem.id')}.property(),
like image 2
MBehtemam Avatar answered Nov 11 '22 02:11

MBehtemam