我給了一個大數組,然後我必須將數據傳輸到一個不同的數組,取決於類型是「客戶」,「商店」還是「地址」,但我得到以下錯誤和我;米不知道爲什麼不確定關於定義錯誤
/*
Exception: ReferenceError: store is not defined
[email protected]/1:56:17
@Scratchpad/1:105:1
*/
var allData = [
{type:"store", data:{store_id: 297, name: "Scotiabank - Main Branch", address_id: 1023}},
{type:"store", data:{store_id: 614, name: "Scotiabank - Hamilton", address_id: 1984}},
{type:"customer", data:{customer_id: 24, store_id:614, first_name: "Jonathan", last_name: "Pym", email: "[email protected]", address_id: 1611, add_date: null}},
{type:"customer", data:{customer_id: 36, store_id:193, first_name: "Kaitlyn", last_name: "Adams", email: "[email protected]", address_id: 5464, add_date: null}},
{type:"customer", data:{customer_id: 73, store_id:297, first_name: "Melissa", last_name: "Bennett", email: "[email protected]", address_id: 4536, add_date: null}},
{type:"address", data:{address_id: 1023, address: "2895 Yonge St.", city:"Toronto", province:"ON", postal_code:"L4C02G"}},
{type:"address", data:{address_id: 1984, address: "3611 Main St. West", city:"Hamilton", province:"ON", postal_code:"R5O8H5"}},
{type:"address", data:{address_id: 1757, address: "1177 Ontario St. Unit 8", city:"Mississauga", province:"ON", postal_code:"L9H6B3"}},
{type:"address", data:{address_id: 4536, address: "3945 John St.", city: "Ajax", province: "ON", postal_code: "L7M4T9"}},
var CustomerDB =
{
customer:[],
address:[],
store:[],
insertData:function (allData)
{
for (var i = 0; i < allData.length; i++)
{
if (allData[i].type == "store")
{
store[i].push(allData[i].store_id, allData[i].name, allData[i].address_id);
}
else if (allData[i].type == "customer")
{
this[i].add_date = new Date();
customer[i].push(allData[i].customer_id, allData[i].store_id, allData[i].first_name, allData[i].last_name, allData[i].email, allData[i].addess_id, allData[i].add_date);
}
else if (allData[i].type == "address")
{
address[i].push(allData[i].address_id, allData[i].address, allData[i].city, allData[i].province, allData[i].cpostal_code);
}
}
}
}
CustomerDB.insertData(allData);
我有一種感覺我回答了同樣的任務離別的地方! –
它的一個不同的錯誤, –
在這裏相同的確切問題http://stackoverflow.com/questions/42181981/adding-elements-from-one-array-to-another/42182030#42182030 –