Extjs4+的image组件如何处理无法找到图片的情况

2018-12-27  本文已影响0人  竹子_331a

我们都知道,img标签有个onerror属性可以控制找不到图片时的处理,那么extjs中如何使用呢?
自己看代码,两种方式
1、动态修改属性

var e = document.getElementById("userPicture"); 
e.setAttribute("onerror","this.src='Main/view/images/default-user.jpg'");

2、在控件的render事件中增加error方法

{
                        
                        xtype: 'image',
                        id:'userPicture',
                        itemId:'userPicture',
                        cls: 'header-right-profile-image',
                        height: 46,
                        width: 46,
                        alt:'个人头像',
                        listeners:{
                            render:function(image){
                                Ext.fly(image.el).on({
                                    'error':function(e){
                                        image.setSrc(defaultUserPicture);
                                    }
                                })
                            }
                        }
                    }
上一篇 下一篇

猜你喜欢

热点阅读