[英]Attribute value turning into array unexpectedly when creating object in javascript dojo
I have below function in my dojo class: 我的dojo类具有以下功能:
dojo.declare("someclass", null, {
getSomeObject: function(id, name, description) {
console.log("id=", id, ", name=", name, ", description=", description);
var newObj = {
"id": id,
"name": name,
"description": description
};
console.log("newObj=", newObj);
return newObj;
}
});
This was fine until I upgraded the product I was working on. 直到我升级正在使用的产品之前,一切都很好。 When I run the code now, somehow inside "newObj", all attribute values are turned into array - ie when "123" is passed as id value to function, inside newObj, "id" attribute value is ["123"].
现在,我以某种方式在“ newObj”内部运行代码时,所有属性值都转换为数组-即,当将“ 123”作为id值传递给函数时,在newObj内,“ id”属性值为[“ 123”]。
I have tried using different ways to create object - with "new Object()", etc. Nothing seems to help. 我尝试使用不同的方式来创建对象-使用“ new Object()”等。似乎没有任何帮助。 When I run the same code in the old product, it works as expected!!!
当我在旧产品中运行相同的代码时,它可以按预期工作!!!
Here is an output from Google Chrome console -- 这是Google Chrome控制台的输出-
id= 5962960 , name= sng2 , description= test
newObj=
Object
_RI: true
description: Array[1]
id: Array[1]
name: Array[1]
__proto__: Object
Any help??? 有帮助吗???
I suppose you are using an ItemFileReadStore
or ItemFileWriteStore
. 我想您正在使用
ItemFileReadStore
或ItemFileWriteStore
。 Then it is absolutely normal, these stores works with arrays internally. 那么这是绝对正常的,这些存储在内部可以处理数组。 To get the value you should do as recommended in the doc:
要获取值,您应该按照文档中的建议进行操作:
store.getValue(storeItem, "property");
or if you're certain that value represented in propery, you can safely typecast by doing + ""
或者,如果您确定该值可以正确表示,则可以通过执行
+ ""
来安全地键入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.