2
var image;
var imgProperties = new Class({
image: new Array(),
json: function() {
var url = protocol + "//" + host + pathname + "/myEchoFile.php";
var jsonRequest = new Request.JSON({
url: url,
onSuccess: function(img) {
this.image[0] = img.name;
this.image[1] = img.width;
this.image[2] = img.height;
alert('img.name=' + this.name); //alerts myImage.jpg
}
}).post();
console.log("this.image[0]=" + this.image[0]); //undefined
//@fixme
//this.image is undefined
}
});
喜, 非常感謝。現在我在另一個類中獲得了imageProperties,我可以爲每個圖像設置圖像屬性。這是一大進步。是否有解決方案可以用其他方法提供這些屬性,例如在setImageDimensions(imageProperties)方法中? – 2011-04-06 09:03:37
是的。 http://jsfiddle.net/dimitar/v38Ee/演示如何在另一個類中使用imgProperties類作爲** mixin **。附:你可能也想接受這個答案:)如果你正在處理多個圖像,那麼將這個圖像指向最後一個圖像是不夠的。我會考慮使用this.images數組或更好,使用mootools-more和'onload'事件中的'Asset.image(s)'來延遲加載數據。 – 2011-04-06 09:39:34