emberjs / ember.js

Ember.js - A JavaScript framework for creating ambitious web applications
https://emberjs.com
MIT License
22.46k stars 4.21k forks source link

{{#each}} attribute binding bug #497

Closed etabard closed 12 years ago

etabard commented 12 years ago

I tried to display an array of pictures with each. The src binding fails and the this.get('src') returns a "String object".

Here is my code :

App = Ember.Application.create();

Em.Image = SC.View.extend({
    tagName: 'img',
    attributeBindings: ['src', 'alt'],
    didChangeSrc: function() {
        console.log(this.get('src'));
    }.observes('src')

})
App.test = ['http://laughingsquid.com/wp-content/uploads/fsm-google-doodle.png', 'http://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif'];
<script type="text/x-handlebars">
    {{#each App.pictures}}
       {{view Em.Image srcBinding="this" alt="no image"}}            
    {{/each}}

</script>

​ Exemple here : http://jsfiddle.net/Raildecom/8Rs5c/

Works outside of each : http://jsfiddle.net/justinbrown/8Rs5c/2/

tchak commented 12 years ago

You can use this as a workaround for now

didChangeSrc: function() {
    this.set('src', String(this.get('src')));
}.observes('src')
etabard commented 12 years ago

Thanks for the quick workaround ;-) It seems odd though !