繁体   English   中英

为什么此对象的属性未定义? 使用Javascript

[英]Why are the properties of this object undefined? Javascript

属性是这种形式的对象:

   var attribute = {
    AttributeId: attributeId,
    EntityId: entityId,
    AttributeDBName: attributeDbName,
    AttributeDisplayName: attributeDisplayName,
    IsSearchable: isSearchable,
    IsDeleted: isDeleted,
    IsVisible: isVisible,
    AttributeTypeId: attributeTypeId,
    Description: description,
    IsSystem: isSystem,
    IsActive: isActive,
    IsUnique: isUnique,
    IsRequired: isRequired,
    IsPersistent: isPersistent,
    DefaultValue: defaultValue
};

然后,该属性与网格ID一起传递给此函数:

function AddAttributeToGrid(attribute, gridId) {

    console.log(attribute); //Works! Displays the attribute.

    var id = a.attributeId;

    console.log(id);//UNDEFINED? WHAT?   

}

如果我创建一个全局变量(我们称其为“ tempAttribute”)并将其设置在AddAttributeToGrid内部,如下所示:

 function AddAttributeToGrid(attribute, gridId) {
    tempAttribute = attribute
}

然后,我可以访问tempAttribute的属性...

为什么我不能从属性中获取数据? 到底是怎么回事?

attributeAttributeId ,而不是attributeId

JavaScript区分大小写。

但这假设您使用定义的attributeId初始化对象。 您的代码中不清楚。

我认为你有

var id = a.attributeId;

代替

var id = attribute.AttributeId;

AddAttributeToGrid函数定义中

暂无
暂无

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

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