(working jsfiddle example here)
var sample_operation_member = {"x": 100, "y": 250};
var sample_undo_member = { "operation" : [sample_operation_member, sample_operation_member,sample_operation_member] };
var hist = {
"undo": [
sample_undo_member,
sample_undo_member,
sample_undo_member,
sample_undo_member
]
}
alert(hist.undo[0].operation[0].x);
,或者更冗長:
var hist = {
undo: [
{"operation": [{"x": 100, "y":100},{"x": 100, "y":100},{"x": 100, "y":100}]},
{"operation": [{"x": 100, "y":100},{"x": 100, "y":100},{"x": 100, "y":100}]},
{"operation": [{"x": 100, "y":100},{"x": 100, "y":100},{"x": 100, "y":100}]},
{"operation": [{"x": 100, "y":100},{"x": 100, "y":100},{"x": 100, "y":100}]}
]
}
alert(hist.undo[0].operation[0].x);
是這個家庭作業? – 2011-01-19 01:59:22
@Toader Mihai Claudiu - 不,我是JSON新手,無法創建對象。 – Rigil 2011-01-19 02:01:57
這篇文章可能會幫助你更好地理解JavaScript對象http://stackoverflow.com/questions/1704618/what-is-the-difference-between-var-thing-and-function-thing-in-javascript – Lance 2011-01-19 02:08:24