如何检查多少未定义的dojo或JavaScript? [英] How to check for multiple undefined in dojo or JavaScript?

查看:159
本文介绍了如何检查多少未定义的dojo或JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有下面的代码段。正如你所看到的,我不得不检查未定义的所有对象和属性 this.view&& this.view.formView&& this.view.formView._dapSections&&& this.view.formView._dapSections.scrollTop



我正在寻找一种检查未定义的方法,在JavaScript或dojo中有任何方法吗?

  if(this.view&& this.view.formView& amp; this.view.formView._dapSections&& this.view.formView ._dapSections.scrollTop){
globals.lastScrollPosition = this.view.formView._dapSections.scrollTop;
}


解决方案

您可能还想尝试lang.exists()
https://dojotoolkit.org/reference-guide/1.10/dojo/_base/lang.html#dojo-base-lang-exists

  if(lang.exists('view.view.formView._dapSections.scrollTop',this){
globals.lastScrollPosition = this.view.formView._dapSections.scrollTop;


I have the below piece of code in my project. As you can see, I had to check the undefined for all the object and properties this.view && this.view.formView && this.view.formView._dapSections && this.view.formView._dapSections.scrollTop.

I'm looking for a way to check undefined for all at once.Is there any way to do that in JavaScript or dojo?

if(this.view && this.view.formView && this.view.formView._dapSections && this.view.formView._dapSections.scrollTop) {
                globals.lastScrollPosition = this.view.formView._dapSections.scrollTop;
            }

解决方案

You might also want to try lang.exists() https://dojotoolkit.org/reference-guide/1.10/dojo/_base/lang.html#dojo-base-lang-exists

if (lang.exists('view.view.formView._dapSections.scrollTop', this) {
    globals.lastScrollPosition = this.view.formView._dapSections.scrollTop;
}

这篇关于如何检查多少未定义的dojo或JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆