我這裡有一個文件,內容如下:
{Item:[{month:'03',items:[{name:'買插座',money:'50',date:'2015-3-1'},{name:'買**',money:'200.5',date:'2015-3-2'}]},{month:'04',items:[{name:'買插座1',money:'50',date:'2015-4-1'},{name:'買**1',money:'200.5',date:'2015-4-2'}]}]}
我想在items後面添加數據,數據格式和上面一樣,請問怎麼弄,謝謝啦!
這是json格式,一層層剝離出來就行了
var a={Item:[{month:'03',items:[{name:'買插座',money:'50',date:'2015-3-1'},{name:'買**',money:'200.5',date:'2015-3-2'}]},{month:'04',items:[{name:'買插座1',money:'50',date:'2015-4-1'},{name:'買**1',money:'200.5',date:'2015-4-2'}]}]};
var item = a['Item'];
for(var i=0;i<item.length;i++){
item[i].items.push({
name:'新插座'+i,
money:'1000',
date:'2015-5-1'
})
}