【发布时间】:2014-06-14 13:08:51
【问题描述】:
我有一个看法:
App.PhotoUploadView = Ember.View.extend({
images: [],
didInsertElement: function() {
var that = this;
var product = this.get('controller').get('model');
var upimages = product.get('upimages');
//this.set('images', []);
upimages.then(function(images) {
images.forEach(function(image, indexI) {
var imageObject = new Object();
imageObject.link = App.appConf.apiPaths.images + image.get('link');
that.get('images').pushObject(imageObject);
});
console.log(that.get('images'))
});
}
});
所以我在这里做的是定义一个最初为空的图像数组,并用通过稍微操作模型的孩子获得的对象填充它......
{{#each product in model}}
{{view App.PhotoUploadView}}
{{/each}}
在应用程序中,我同时插入了许多 PhotoUploadView;问题是,不是为 PhotoUploadView 的每个实例使用不同的图像数组,而是每个实例都有一个包含所有图像的图像数组,就像该数组在实例之间共享一样;
如果我删除对 this.set('images', []); 的评论在 didInsertElement 函数中,一切正常;所以问题是:图像数组在 PhotoUploadView 实例之间共享?还是我错过了什么……?
【问题讨论】:
标签: ember.js