繁体   English   中英

灰烬加载异步属性

[英]Ember load async property

在我的余烬应用程序中,我想加载图像。 我的模型具有服务器图像,因此我异步加载它们。

fotos: DS.hasMany('foto', { async: true })

每个“ foto”都有一个文件位置“ fileName:DS.attr()”的属性。 现在,在我的路线的控制器中,需要扩展路径以将图像加载为背景图像:

loadImage: function(){
    var path;
    this.get('model').forEach(function(art){
        art.get('fotos').then(function(fotos){
            path = fotos.get('content')[0].get('fileName');
        })
    });
    return "background-image:url(" + path +")";
}.property()

(日志说)loadImage或path包含图像的正确路径。 当我尝试使用{{loadImage}}渲染模板时,它永远不会出现。 我该如何改变?

路径是异步设置的,您将立即返回一个空值。

firstImagePath: Em.computed.alias('firstObject.fotos.fileName'), // this assumes you're in an ArrayController

loadImage: function(){
    var path = this.get('firstImagePath');
    return "background-image:url(" + path +")";
}.property('firstImagePath')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM