简体   繁体   English

this.SOMETHING始终返回未定义-extjs

[英]this.SOMETHING always returns undefined - extjs

I have a portlet that includes a tabbed panel. 我有一个包含选项卡式面板的portlet。 In that panel is a chart. 在该面板中是一个图表。 In one of the chart's functions, I do a console.log(this) and am able to view all of the contents. 在图表的功能之一中,我执行console.log(this)并能够查看所有内容。 However, my main intention is to use the value this.ownerCt , this says that it exists, but when I try to use it, or console.log it, it reports as undefined. 但是,我的主要目的是使用值this.ownerCt ,它表示它存在,但是当我尝试使用它或console.log时,它报告为未定义。 If I do a this.id or this.idname I get the actual ids. 如果我执行this.idthis.idname获得实际的ID。

Problem: Why would this.SOMETHING return undefined if there is a value for it in this ? 问题:为什么会this.SOMETHING返回undefined如果在它的值this

Some code tidbits: here is console.log(this) . 一些代码花絮:这是console.log(this)

Ext.Class.newClass
  additionalCls: Array[2]
  body: Ext.Element.Ext.core.Element
  childEls: Array[1]
  collapseDirection: "top"
  componentCls: "x-panel"
  componentLayout: Ext.Class.newClass
  componentLayoutCounter: 3
  container: Ext.Element.Ext.core.Element
  dockedItems: Ext.Class.newClass
  el: Ext.Element.Ext.core.Element
  id: "stackedbarportlet-1055"
  itemId: "graph"
  items: Ext.Class.newClass
  ownerCt: Ext.Class.newClass
  xtype: "stackedbarportlet"

I took a few instances out, but this is the general output of it! 我拿了几个实例,但这是它的一般输出!

console.log(this.ownerCt) results in: undefined . console.log(this.ownerCt)结果为: undefined

<script>

var t1="";
var t2;

if (t1===undefined)
{
alert("t1 is undefined");
}
if (t2===undefined)
{
alert("t2 is undefined");
}

</script>

if you run that t2 is undefined probably this.ownerCt has no value 如果运行t2未定义,可能this.ownerCt没有值

You may find your answer here . 您可以在这里找到答案。 It seems that sometimes console.log() invocations are queued and eventually invoked after the end of the current statement, so their output don't necessarily reflect the object state exactly in the moment as it is in the code. 似乎有时console.log()调用被排队,并最终在当前语句结束之后被调用,因此它们的输出并不一定像代码中那样立即反映对象状态。

At least, I experienced similar behavior when I was overriding the constructor function in custom defined ExtJS's store. 至少当我在自定义定义的ExtJS的存储中重写构造函数时,我遇到了类似的行为。

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

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