다음과 같은 개체가 있습니다.
function Point(x,y)
{
this.coorX = x;
this.coorY = y;
}
function Node(id,x,y)
{
this.id = id;
this.point = new Point(x,y);
this.getDescription = function(){
return this.id + ': (' + this.punto.coorX + ', ' + this.punto.coorY + ')';
}
}
다음을 사용하여 json 형식으로 노드 목록을 내 보냅니다.
JSON.stringify(NodeList);
json :
{"NodeList":[{"id":0,"point":{"coorX":15,"coorY":15},"$$hashKey":"004"},{"id":1,"point":{"coorX":15,"coorY":151},"$$hashKey":"009"},{"id":2,"point":{"coorX":25,"coorY":15},"$$hashKey":"00E"}]}
다음을 사용하여 동일한 json을 가져온 후
NodeList = JSON.parse(text);
가져 오기 후 어떻게 Node
기능을 사용할 수 getDescription()
있습니까?
다음과 같이 노드를 다시 만들 수 있습니다.
var items = NodeList.NodeList,
nodes = [];
for(var i = 0; i < items.lenght; i++) {
var item = items[i],
point = item.point,
node = new Node(item.id, point.coorX, point.coorY);
nodes.push(node);
}
// call getDescription of first node
nodes[0].getDescription();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다