为什么未定义此对象的属性?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的属性。。。
为什么我不能从属性中获取数据?发生了什么事?
attribute
的属性是AttributeId
,而不是attributeId
。
JavaScript区分大小写。
但这是假设您首先使用定义的attributeId
初始化了对象。这在您的代码中并不清楚。
我想你有
var id = a.attributeId;
而不是
var id = attribute.AttributeId;
在AddAttributeToGrid
函数定义内部
相关文章:
- 保存具有相同属性 JavaScript 的元素上的值
- DOM 元素上的空样式属性:JavaScript
- 基于一个属性Javascript检索多个对象
- xml获取属性javascript不会;无法处理childNodes
- 当输入填充了必需的属性javascript/html/css时,如何更改焦点颜色
- 如何处理未定义属性的未定义属性 javascript 类型错误
- 向嵌套对象添加属性 - Javascript
- 属性 Javascript 的访问属性
- 更改链中的 css 属性 - JavaScript
- 更改属性 Javascript 方式的值
- 如何从 url 解析 xml 获取属性 javascript
- 语法错误:缺少:在属性 javascript 之后
- 创建 if 条件基于 CSS 属性 -- JavaScript
- 访问节点的属性javascript二进制搜索树
- 访问父函数属性Javascript
- 为什么未定义此对象的属性?Javascript
- 访问私有属性Javascript OOP
- 访问数组中的属性?(Javascript)
- 动态添加参数作为对象的属性-JavaScript
- 冲突/方法/属性Javascript错误