mch20093493 2016-06-06 09:20 采纳率: 100%
浏览 1049
已采纳

Ext中的如下代码应该怎么理解

items = [];
tempConfig1=me.getNodeConfig(node);
tempConfig2=Ext.clone(tempConfig1);
tempValues=(tempConfig1||{})["moreValue"]||'';
if(!Ext.isEmpty(tempValues)){
tempValues=tempValues.split(",");
if(tempValues){
if(tempValues.length==2){
startValue=tempValues[0];
endValue=tempValues[1];
}else if(tempValues.length==1){
startValue=tempValues[0];
}
}
};
items.push(Ext.apply(tempConfig1, {
labelWidth : Vbap.byteLengthOf(node.getAttribute('label')) * 8,
width : Vbap.byteLengthOf(node.getAttribute('label')) * 8 + 123,
value:startValue,
allowBlank : node.getAttribute('isRequired') == "false" ? "true" : "false"
}), {
xtype : 'displayfield',
value : '-',
width : 4
}, Ext.apply(tempConfig2, {
hideLabel : true,
width : 118,
value:endValue
}));

如上代码中的node如下图:
图片说明

如上代码中tempValues=(tempConfig1||{})["moreValue"]||''; 这段代码应该怎么理解

  • 写回答

1条回答 默认 最新

  • Go 旅城通票 2016-06-06 09:38
    关注

    tempConfig1是否获取到,如果为null则用{}替代,这样调用对象属性["moreValue"]就不会出现null引用而报错
    tempConfig1||{})["moreValue"]没有获取到值就用空字符串代替,防止{}["moreValue"]==》undefined,这样使用tempValues变量值时如果调用toString什么的会报错

    这个是js语法,和ext没关系,多学点js基础

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器