gpt4 book ai didi

javascript - Ext 3 教程代码与 Ext 4 不兼容

转载 作者:行者123 更新时间:2023-11-30 18:43:17 27 4
gpt4 key购买 nike

我想重写 this从 Ext3 到 Ext4 的教程。但是从我能够观察到的情况来看,createDelegate 函数已被删除(可能与许多其他事情一样)并且它不起作用。我试过调用 call/apply 而不是这个未定义的 createDelegate 但后来我在代码中遇到了其他问题 - this.msgEl 未定义。如何解决这个问题?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Panel</title>
<link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
<script type="text/javascript" src="bootstrap.js"></script>
<script type="text/javascript" src="ext-all.js"></script>
<script type="text/javascript" src="shared/examples.js"></script>
<style type="text/css">
body {
padding: 10px;
}

.x-popup-el {
position: absolute;
background: transparent url(resources/images/default/qtip/tip-sprite.gif) no-repeat right 0;
border-left:1px solid #99BBE8;
padding-right:6px;
overflow:hidden;
zoom:1;
}

.x-popup-body {
background: transparent url(resources/images/default/qtip/tip-sprite.gif) no-repeat 0 -62px;
padding-top:3px;
overflow:hidden;
zoom:1;
}

.x-popup-message-text {
padding:0 20px 0 10px;
font-family:helvetica,tahoma,verdana,sans-serif;
}

.x-popup-message-text.error {
color: red;
}
</style>
<script type="text/javascript">

Ext.ux.PopupMessage = Ext.extend(Object, {
init: function(c) {
this.client = c;
c.showMessage = this.showMessage.apply(this);
if (c.rendered) {
this.onRender(c);
} else {
c.on('render', this.onRender, this);
}
},

onRender: function(c) {
this.el = c.el.createChild(
'<div class="x-hidden x-popup-el">' +
'<div class="x-popup-body">' +
'<span class="x-popup-message-text"></span>' +
'</div>' +
'</div>'
);
this.el.syncFx();
this.msgEl = this.el.child('span.x-popup-message-text');
},

showMessage: function(m, cls) {
if (this.fading) {
clearTimeout(this.fading);
this.fading = 0;
}
console.log(this);
this.msgEl.dom.innerHTML = m;
if (cls) {
this.msgEl.extraCls = cls;
this.msgEl.addClass(cls);
}
this.el.stopFx();
this.el.alignTo(this.client.el, "bl-bl", [0, -1]);
this.el.slideIn('b').fadeIn({
callback: this.hide,
scope: this
});
},

hide: function() {
this.fading = this.el.fadeOut.defer(5000, this.el, [{
callback: function() {
this.msgEl.removeClass(this.msgEl.extraCls);
},
scope: this
}]);
}
});

Ext.onReady(function(){
p = new Ext.Panel({
plugins: new Ext.ux.PopupMessage(),
frame: true,
title: 'My Panel',
renderTo: document.body,
width: 400,
html: Ext.example.bogusMarkup
});

new Ext.Toolbar({
renderTo: document.body,
style: {
'margin-top': '20px'
},
width: 400,
items: [{
text: 'Show message',
handler: function() {
p.showMessage("Hello world!");
}
}, {
text: 'Show error message',
handler: function() {
p.showMessage("Something bad!", "error");
}
}]
});
});
</script>
</head>
<body>
</body>
</html>

错误:

this.msgEl is undefined
file:///C:/Work/learn-tmp/Popup.html
Line 76

最佳答案

createDelegate 现在是一个静态方法——所有 native JS 对象原型(prototype)覆盖都已在 Ext 4 中删除。因此,您可以使用 Ext.Function 而不是 myFn.createDelegate(this)。 createDelegate(myFn, this) 或更可取的别名 Ext.bind(myFn, this)

关于javascript - Ext 3 教程代码与 Ext 4 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6228430/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com