SC.ImageView throws error when setting value
When setting the value
property of a subclassed SproutCore image view (SC.ImageView
) a runtime error is thrown:
In Safari and Firefox:
TypeError: Result of expression 'elem.setAttribute' [undefined] is not a function.
In Chrome:
Uncaught TypeError: Object DigDeeper.ZoomLayerView:sc398 has no method 'setAttribute'
The error occurs in /static/sproutcore/foundation/en/current/javascript.js
on the following code (line 4735):
// convert the value to a string (all browsers do this but IE) see
// #1070 (jQuery)
if ( set ) elem.setAttribute( name, "" + value );
The image is loaded but does not display.
I am using the current version of sproutcore from the ruby gem (appears to be 1.4.5).
How can I re开发者_运维技巧solve this issue?
Here is the source:
DigDeeper.ZoomTileView = SC.ImageView.extend({
// Properties
zoom: null,
layer: null,
scaleIndex: null,
column: null,
row: null,
// Overridden properties
classNames: [ 'zoom-tile-view' ],
// Computed properties
scale: function () {
return Math.pow( 2, this.get( 'scaleIndex' ) );
}.property( 'scaleIndex' ),
id: function () {
return "%@.%@.%@.%@".fmt(
DigDeeper.ZoomTileView.zeroPad( 0, 5 ),
DigDeeper.ZoomTileView.zeroPad( this.get( 'scale' ), 0 ),
DigDeeper.ZoomTileView.zeroPad( this.get( 'column' ), 0 ),
DigDeeper.ZoomTileView.zeroPad( this.get( 'row' ), 0 )
);
}.property('layer','scaleIndex','column','row').cacheable(),
value: function () {
return "/static/dig_deeper/en/current/resources/images/%@.png".fmt( this.get( 'id' ) );
}.property( 'id' ),
});
You have a trailing comma on your value method.
Removing it might solve you issue.
What does your SC.ImageView design look like? Here is an example of something I do to pop up a little progress spinner when a really long server call is processing:
validateProgressImage: SC.ImageView.design({
layout: { top: 63, left: 150, height: 16, width: 16 },
value: sc_static("images/ajax-loader.gif"),
canLoadInBackground: true,
useCanvas: NO,
useImageQueue: NO,
isVisible: YES
}),
My ajax-loader.gif file is located in my resources/images directory.
精彩评论