具有向JSON添加属性的KineticJS对象 [英] KineticJS object with added property to JSON
本文介绍了具有向JSON添加属性的KineticJS对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将KineticJS对象(具有一个添加的属性)序列化为JSON,但是如果我调用JSON.stringify(test);
,它将仅返回KineticJS对象的JSON表示而没有我的添加属性.有人知道,请问哪里可能有问题?
I am trying to serialize KineticJS object (with one added property) to JSON, but if I call the JSON.stringify(test);
, it returns only JSON representation of KineticJS object without my added property. Does anybody know, where could be a problem, please?
test = new Kinetic.Line(
{
points : [ 29, 30, 31, 32 ],
stroke : 'black',
strokeWidth : 2,
lineJoin : 'round',
id : '#line'
});
test.obj = "my own property";
JSON.stringify(test);
返回
{"attrs":{"points":[{"x":29,"y":30},{"x":31,"y":32}],"stroke":"black","strokeWidth":2,"lineJoin":"round","id":"#line"},
"nodeType":"Shape","shapeType":"Line"}"
但是我还需要有关test.obj的信息.
But I need also information about test.obj..
推荐答案
您可以这样做:
var test = new Object();
test.kinetic = new Kinetic.Line(
{
points : [ 29, 30, 31, 32 ],
stroke : 'black',
strokeWidth : 2,
lineJoin : 'round',
id : '#line'
});
test.obj = "my own property";
console.log(JSON.stringify(test));
这篇关于具有向JSON添加属性的KineticJS对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文