2016-11-10 194 views
0

我正在編寫一些代碼來從Google表單中識別學校。除非我減少If..else語句的數量,否則該函數將不會運行。目前大約有204個。當我刪除這些函數時,會導致我相信它,因爲if..else結構太大。Javascript If..else statement too long

如何簡化下面的代碼以便能夠運行。任何幫助是非常讚賞:)

if (school == "Abernethy Primary") {group ="/Primary/Abernethy Primary/"; domain ="GrantownGrammar.org.uk"; schoolType ="Primary";} 
    else if (school == "Acharacle Primary") {group ="/Primary/Acharacle Primary/"; domain ="ArdnamurchanHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Achiltibuie Primary") {group ="/Primary/Achiltibuie Primary/"; domain ="UllapoolHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Aldourie Primary") {group ="/Primary/Aldourie Primary/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Alness Academy") {group ="/Secondary/Alness Academy/"; domain ="AlnessAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Altnaharra Primary") {group ="/Primary/Altnaharra Primary/"; domain ="FarrHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Alvie Primary") {group ="/Primary/Alvie Primary/"; domain ="KingussieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Applecross Primary") {group ="/Primary/Applecross Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Ardersier Primary") {group ="/Primary/Ardersier Primary/"; domain ="CullodenAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Ardgour Primary") {group ="/Primary/Ardgour Primary/"; domain ="ArdnamurchanHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Ardnamurchan High School") {group ="/Secondary/Ardnamurchan High School/"; domain ="ArdnamurchanHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Ardross Primary") {group ="/Primary/Ardross Primary/"; domain ="AlnessAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Arisaig Primary") {group ="/Primary/Arisaig Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Auchtertyre Primary") {group ="/Primary/Auchtertyre Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Auldearn Primary") {group ="/Primary/Auldearn Primary/"; domain ="NairnAcademy.net"; schoolType ="Primary";} 
    else if (school == "Aviemore Primary") {group ="/Primary/Aviemore Primary/"; domain ="KingussieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Avoch Primary") {group ="/Primary/Avoch Primary/"; domain ="FortroseAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Badcaul Primary") {group ="/Primary/Badcaul Primary/"; domain ="UllapoolHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Ballachulish Primary") {group ="/Primary/Ballachulish Primary/"; domain ="KinlochlevenHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Balloch Primary") {group ="/Primary/Balloch Primary/"; domain ="CullodenAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Balnain Primary") {group ="/Primary/Balnain Primary/"; domain ="GlenurquhartHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Banavie Primary") {group ="/Primary/Banavie Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Beauly Primary") {group ="/Primary/Beauly Primary/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Ben Wyvis Primary") {group ="/Primary/Ben Wyvis Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Bishop Eden Primary") {group ="/Primary/Bishop Eden Primary/"; domain ="InvernessHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Black Isle Education Centre") {group ="/Special/Black Isle Education Centre/"; domain ="Highlandschools.net"; schoolType ="Special";} 
    else if (school == "Bonar Bridge Primary") {group ="/Primary/Bonar Bridge Primary/"; domain ="DornochAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Bower Primary") {group ="/Primary/Bower Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Bridgend Primary") {group ="/Primary/Bridgend Primary/"; domain ="AlnessAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Broadford Primary") {group ="/Primary/Broadford Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Brora Primary") {group ="/Primary/Brora Primary/"; domain ="GolspieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Bualnaluib Primary") {group ="/Primary/Bualnaluib Primary/"; domain ="GairlochHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Bun-sgoil Ghaidhlig Inbhir Nis") {group ="/Primary/Bun-sgoil Ghaidhlig Inbhir Nis/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Bun-sgoil Ghaidhlig Loch Abar") {group ="/Primary/Bun-sgoil Ghaidhlig Loch Abar/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Bun-sgoil Shll-ite") {group ="/Primary/Bun-sgoil Shll-ite/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Canisbay Primary") {group ="/Primary/Canisbay Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Canna Primary") {group ="/Primary/Canna Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Cannich Bridge Primary") {group ="/Primary/Cannich Bridge Primary/"; domain ="GlenurquhartHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Caol Primary") {group ="/Primary/Caol Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Carbost Primary") {group ="/Primary/Carbost Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Carrbridge Primary") {group ="/Primary/Carrbridge Primary/"; domain ="GrantownGrammar.org.uk"; schoolType ="Primary";} 
    else if (school == "Castletown Primary") {group ="/Primary/Castletown Primary/"; domain ="ThursoHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Cauldeen Primary") {group ="/Primary/Cauldeen Primary/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Cawdor Primary") {group ="/Primary/Cawdor Primary/"; domain ="NairnAcademy.net"; schoolType ="Primary";} 
    else if (school == "Central Primary") {group ="/Primary/Central Primary/"; domain ="InvernessHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Charleston Academy") {group ="/Secondary/Charleston Academy/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Coulhill Primary") {group ="/Primary/Coulhill Primary/"; domain ="AlnessAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Cradlehall Primary") {group ="/Primary/Cradlehall Primary/"; domain ="CullodenAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Craighill Primary") {group ="/Primary/Craighill Primary/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Cromarty Primary") {group ="/Primary/Cromarty Primary/"; domain ="FortroseAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Crossroads Primary") {group ="/Primary/Crossroads Primary/"; domain ="ThursoHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Crown Primary") {group ="/Primary/Crown Primary/"; domain ="MillburnAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Croy Primary") {group ="/Primary/Croy Primary/"; domain ="CullodenAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Culbokie Primary") {group ="/Primary/Culbokie Primary/"; domain ="FortroseAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Culloden Academy") {group ="/Secondary/Culloden Academy/"; domain ="CullodenAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Dalneigh Primary") {group ="/Primary/Dalneigh Primary/"; domain ="InvernessHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Daviot Primary") {group ="/Primary/Daviot Primary/"; domain ="MillburnAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Deshar Primary") {group ="/Primary/Deshar Primary/"; domain ="GrantownGrammar.org.uk"; schoolType ="Primary";} 
    else if (school == "Dingwall Academy") {group ="/Secondary/Dingwall Academy/"; domain ="DingwallAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Dingwall Primary") {group ="/Primary/Dingwall Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Dochgarroch Primary") {group ="/Primary/Dochgarroch Primary/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Dornoch Academy") {group ="/Secondary/Dornoch Academy/"; domain ="DornochAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Dornoch Primary") {group ="/Primary/Dornoch Primary/"; domain ="DornochAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Drakies Primary") {group ="/Primary/Drakies Primary/"; domain ="MillburnAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Drummond School") {group ="/Special/Drummond School/"; domain ="Highlandschools.net"; schoolType ="Special";} 
    else if (school == "Dunbeath Primary") {group ="/Primary/Dunbeath Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Duncan Forbes Primary") {group ="/Primary/Duncan Forbes Primary/"; domain ="CullodenAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Dunvegan Primary") {group ="/Primary/Dunvegan Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Durness Primary") {group ="/Primary/Durness Primary/"; domain ="KinlochbervieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Duror Primary") {group ="/Primary/Duror Primary/"; domain ="KinlochlevenHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Edderton Primary") {group ="/Primary/Edderton Primary/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Edinbane Primary") {group ="/Primary/Edinbane Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Eigg Primary") {group ="/Primary/Eigg Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Elgol Primary") {group ="/Primary/Elgol Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Farr High School") {group ="/Secondary/Farr High School/"; domain ="FarrHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Farr Primary (Inv)") {group ="/Primary/Farr Primary (Inv)/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Farr Primary (Suth)") {group ="/Primary/Farr Primary (Suth)/"; domain ="FarrHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Ferintosh Primary") {group ="/Primary/Ferintosh Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Fortrose Academy") {group ="/Secondary/Fortrose Academy/"; domain ="FortroseAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Foyers Primary") {group ="/Primary/Foyers Primary/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Gairloch High School") {group ="/Secondary/Gairloch High School/"; domain ="GairlochHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Gairloch Primary") {group ="/Primary/Gairloch Primary/"; domain ="GairlochHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Gergask Primary") {group ="/Primary/Gergask Primary/"; domain ="KingussieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Gledfield Primary") {group ="/Primary/Gledfield Primary/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Glen Urquhart High School") {group ="/Secondary/Glen Urquhart High School/"; domain ="GlenurquhartHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Glencoe Primary") {group ="/Primary/Glencoe Primary/"; domain ="KinlochlevenHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Glenelg Primary") {group ="/Primary/Glenelg Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Glenurquhart Primary") {group ="/Primary/Glenurquhart Primary/"; domain ="GlenurquhartHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Golspie High School") {group ="/Secondary/Golspie High School/"; domain ="GolspieHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Golspie Primary") {group ="/Primary/Golspie Primary/"; domain ="GolspieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Grantown Grammar School") {group ="/Secondary/Grantown Grammar School/"; domain ="GrantownGrammar.org.uk"; schoolType ="Secondary";} 
    else if (school == "Grantown Primary") {group ="/Primary/Grantown Primary/"; domain ="GrantownGrammar.org.uk"; schoolType ="Primary";} 
    else if (school == "Halkirk Primary") {group ="/Primary/Halkirk Primary/"; domain ="ThursoHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Helmsdale Primary") {group ="/Primary/Helmsdale Primary/"; domain ="GolspieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Hill of Fearn Primary") {group ="/Primary/Hill of Fearn Primary/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Hilton of Cadboll Primary") {group ="/Primary/Hilton of Cadboll Primary/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Hilton Primary") {group ="/Primary/Hilton Primary/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Holm Primary") {group ="/Primary/Holm Primary/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Inshes Primary") {group ="/Primary/Inshes Primary/"; domain ="MillburnAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Inver Primary") {group ="/Primary/Inver Primary/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Invergarry Primary") {group ="/Primary/Invergarry Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Invergordon Academy") {group ="/Secondary/Invergordon Academy/"; domain ="InvergordonAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Inverie Primary") {group ="/Primary/Inverie Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Inverlochy Primary") {group ="/Primary/Inverlochy Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Inverness High School") {group ="/Secondary/Inverness High School/"; domain ="InvernessHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Inverness Royal Academy") {group ="/Secondary/Inverness Royal Academy/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Keiss Primary") {group ="/Primary/Keiss Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kilchoan Primary") {group ="/Primary/Kilchoan Primary/"; domain ="ArdnamurchanHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kilchuimen Academy") {group ="/Secondary/Kilchuimen Academy/"; domain ="KilchuimenAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Kilchuimen Primary") {group ="/Primary/Kilchuimen Primary/"; domain ="KilchuimenAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Kilmuir Primary") {group ="/Primary/Kilmuir Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kiltearn Primary") {group ="/Primary/Kiltearn Primary/"; domain ="AlnessAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Kingussie High School") {group ="/Secondary/Kingussie High School/"; domain ="KingussieHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Kingussie Primary") {group ="/Primary/Kingussie Primary/"; domain ="KingussieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kinlochbervie High School") {group ="/Secondary/Kinlochbervie High School/"; domain ="KinlochbervieHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Kinlochbervie Primary") {group ="/Primary/Kinlochbervie Primary/"; domain ="KinlochbervieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kinlochewe Primary") {group ="/Primary/Kinlochewe Primary/"; domain ="GairlochHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kinlochleven High School") {group ="/Secondary/Kinlochleven High School/"; domain ="KinlochlevenHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Kinlochleven Primary") {group ="/Primary/Kinlochleven Primary/"; domain ="KinlochlevenHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kinmylies Primary") {group ="/Primary/Kinmylies Primary/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Kirkhill Primary") {group ="/Primary/Kirkhill Primary/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Knockbreck Primary (Dunvegan)") {group ="/Primary/Knockbreck Primary (Dunvegan)/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Knockbreck Primary (Tain)") {group ="/Primary/Knockbreck Primary (Tain)/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Kyle Primary") {group ="/Primary/Kyle Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Kyleakin Primary") {group ="/Primary/Kyleakin Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Lady Lovat Primary") {group ="/Primary/Lady Lovat Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Lairg Primary") {group ="/Primary/Lairg Primary/"; domain ="GolspieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Loch Duich Primary") {group ="/Primary/Loch Duich Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Lochaber High School") {group ="/Secondary/Lochaber High School/"; domain ="LochaberHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Lochaline Primary") {group ="/Primary/Lochaline Primary/"; domain ="ArdnamurchanHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Lochardil Primary") {group ="/Primary/Lochardil Primary/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Lochcarron Primary") {group ="/Primary/Lochcarron Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Lochinver Primary") {group ="/Primary/Lochinver Primary/"; domain ="UllapoolHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Lundavra Primary") {group ="/Primary/Lundavra Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Lybster Primary") {group ="/Primary/Lybster Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Macdiarmid Primary") {group ="/Primary/Macdiarmid Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Mallaig High School") {group ="/Secondary/Mallaig High School/"; domain ="MallaigHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Mallaig Primary") {group ="/Primary/Mallaig Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Marybank Primary") {group ="/Primary/Marybank Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Melvich Primary") {group ="/Primary/Melvich Primary/"; domain ="FarrHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Merkinch Primary") {group ="/Primary/Merkinch Primary/"; domain ="InvernessHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Millbank Primary") {group ="/Primary/Millbank Primary/"; domain ="NairnAcademy.net"; schoolType ="Primary";} 
    else if (school == "Millburn Academy") {group ="/Secondary/Millburn Academy/"; domain ="MillburnAcademy.org.uk"; schoolType ="Secondary";} 
    else if (school == "Miller Academy Primary") {group ="/Primary/Miller Academy Primary/"; domain ="ThursoHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Milton of Leys Primary") {group ="/Primary/Milton of Leys Primary/"; domain ="MillburnAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Milton Primary") {group ="/Primary/Milton Primary/"; domain ="InvergordonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Mount Pleasant Primary") {group ="/Primary/Mount Pleasant Primary/"; domain ="ThursoHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Muck Primary") {group ="/Primary/Muck Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Muirtown Primary") {group ="/Primary/Muirtown Primary/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Mulbuie Primary") {group ="/Primary/Mulbuie Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Munlochy Primary") {group ="/Primary/Munlochy Primary/"; domain ="FortroseAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Nairn Academy") {group ="/Secondary/Nairn Academy/"; domain ="NairnAcademy.net"; schoolType ="Secondary";} 
    else if (school == "Newmore Primary") {group ="/Primary/Newmore Primary/"; domain ="InvergordonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Newton Park Primary") {group ="/Primary/Newton Park Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Newtonmore Primary") {group ="/Primary/Newtonmore Primary/"; domain ="KingussieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "North Kessock Primary") {group ="/Primary/North Kessock Primary/"; domain ="FortroseAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Noss Primary") {group ="/Primary/Noss Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Obsdale Primary") {group ="/Primary/Obsdale Primary/"; domain ="AlnessAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Park Primary School") {group ="/Primary/Park Primary School/"; domain ="InvergordonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Pennyland Primary") {group ="/Primary/Pennyland Primary/"; domain ="ThursoHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Plockton High School") {group ="/Secondary/Plockton High School/"; domain ="PlocktonHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Plockton Primary") {group ="/Primary/Plockton Primary/"; domain ="PlocktonHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Poolewe Primary") {group ="/Primary/Poolewe Primary/"; domain ="GairlochHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Portree High School") {group ="/Secondary/Portree High School/"; domain ="PortreeHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Portree Primary") {group ="/Primary/Portree Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Raasay Primary") {group ="/Primary/Raasay Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Raigmore Primary") {group ="/Primary/Raigmore Primary/"; domain ="MillburnAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Reay Primary") {group ="/Primary/Reay Primary/"; domain ="ThursoHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Resolis Primary") {group ="/Primary/Resolis Primary/"; domain ="FortroseAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Rogart Primary") {group ="/Primary/Rogart Primary/"; domain ="GolspieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Rosebank Primary") {group ="/Primary/Rosebank Primary/"; domain ="NairnAcademy.net"; schoolType ="Primary";} 
    else if (school == "Rosehall Primary") {group ="/Primary/Rosehall Primary/"; domain ="GolspieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Roybridge Primary") {group ="/Primary/Roybridge Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Rum Primary") {group ="/Primary/Rum Primary/"; domain ="MallaigHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Scoraig School") {group ="/Primary/Scoraig School/"; domain ="UllapoolHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Scourie Primary") {group ="/Primary/Scourie Primary/"; domain ="KinlochbervieHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Shieldaig Primary") {group ="/Primary/Shieldaig Primary/"; domain ="GairlochHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Smithton Primary") {group ="/Primary/Smithton Primary/"; domain ="CullodenAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "South Lodge Primary") {group ="/Primary/South Lodge Primary/"; domain ="InvergordonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Spean Bridge Primary") {group ="/Primary/Spean Bridge Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "St Bride's Primary") {group ="/Primary/St Bride's Primary/"; domain ="KinlochlevenHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "St Clement's School") {group ="/Special/St Clement's School/"; domain ="Highlandschools.net"; schoolType ="Special";} 
    else if (school == "St Columba's RC Primary") {group ="/Primary/St Columba's RC Primary/"; domain ="LochaberHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "St Duthus School") {group ="/Special/St Duthus School/"; domain ="Highlandschools.net"; schoolType ="Special";} 
    else if (school == "St Joseph's RC Primary") {group ="/Primary/St Joseph's RC Primary/"; domain ="InvernessHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Staffin Primary") {group ="/Primary/Staffin Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Strathconon Primary") {group ="/Primary/Strathconon Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Strathdearn Primary") {group ="/Primary/Strathdearn Primary/"; domain ="MillburnAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Stratherrick Primary") {group ="/Primary/Stratherrick Primary/"; domain ="InvernessRoyalAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Strathgarve Primary") {group ="/Primary/Strathgarve Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Strathpeffer Primary") {group ="/Primary/Strathpeffer Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Strontian Primary") {group ="/Primary/Strontian Primary/"; domain ="ArdnamurchanHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Struan Primary") {group ="/Primary/Struan Primary/"; domain ="PortreeHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Tain Royal Academy") {group ="/Secondary/Tain Royal Academy/"; domain ="TainRoyalAcademy.net"; schoolType ="Secondary";} 
    else if (school == "Tarbat Old Primary") {group ="/Primary/Tarbat Old Primary/"; domain ="TainRoyalAcademy.net"; schoolType ="Primary";} 
    else if (school == "Tarradale Primary") {group ="/Primary/Tarradale Primary/"; domain ="DingwallAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Teanassie Primary") {group ="/Primary/Teanassie Primary/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "The Bridge") {group ="/Special/The Bridge/"; domain ="Highlandschools.net"; schoolType ="Special";} 
    else if (school == "Thrumster Primary") {group ="/Primary/Thrumster Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Thurso High School") {group ="/Secondary/Thurso High School/"; domain ="ThursoHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Tomnacross Primary") {group ="/Primary/Tomnacross Primary/"; domain ="CharlestonAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Tongue Primary") {group ="/Primary/Tongue Primary/"; domain ="FarrHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Tore Primary") {group ="/Primary/Tore Primary/"; domain ="FortroseAcademy.org.uk"; schoolType ="Primary";} 
    else if (school == "Ullapool High School") {group ="/Secondary/Ullapool High School/"; domain ="UllapoolHigh.org.uk"; schoolType ="Secondary";} 
    else if (school == "Ullapool Primary") {group ="/Primary/Ullapool Primary/"; domain ="UllapoolHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Watten Primary") {group ="/Primary/Watten Primary/"; domain ="WickHigh.org.uk"; schoolType ="Primary";} 
    else if (school == "Wick High School") {group ="/Secondary/Wick High School/"; domain ="WickHigh.org.uk"; schoolType ="Secondary";} 
+0

你可以存儲在數據庫中的那些值的數據循環做查詢? 那些if-else是瘋狂的。 –

+0

沒有,很簡單的設置 –

+4

而不是做如果其他,我的解決方案是維護一個數組與所有values.And然後編寫一個函數返回相應的值。 –

回答

1

只要把你的數據轉換成目標

var schools = { 
    "Abernethy Primary": { 
     "group":"/Primary/Abernethy Primary/", 
     "domain":"GrantownGrammar.org.uk", 
     "schoolType":"Primary" 
    }, 
    ... 
}; 

而且通過

var group = schools[school].group; 
var domain = schools[school].domain; 
var schoolType = schools[school].schoolType; 

而更好的方式獲得所需的增值經銷商把這些數據轉換爲單獨的文件。

+0

會給這個嘗試。 –

+0

在Google腳本中編寫此代碼時,我添加了更多對象或If語句,如上面的函數}上面的函數}不會變綠以顯示其關閉。隨着我添加更多,它變紅並且不會運行。這是因爲if語句太多嗎? @ br3t –

+0

抱歉,我無法幫助您處理Google腳本 – br3t

0

如果您不能將這些值存儲在數據庫或外部文件中,那麼您運氣不好。您可以將它縮短一點,並通過將值存儲在數組中來組織。

然後你就可以通過

var schools = { 
 
    Primary: [ 
 
    ["Abernethy Primary",  "GrantownGrammar.org.uk"], 
 
    ["Acharacle Primary",  "ArdnamurchanHigh.org.uk"], 
 
    // etc 
 
    ], 
 
    Secondary: [ 
 
    ["Ullapool High School", "UllapoolHigh.org.uk"], 
 
    ["Wick High School",  "WickHigh.org.uk"], 
 
    // etc 
 
    ] 
 
}; 
 

 
function findData(schoolName) { 
 
    for (var t in schools) { 
 
    if (schools.hasOwnProperty(t)) { 
 
     for (var i = 0; i < schools[t].length; i++) { 
 
     if (schoolName == schools[t][i][0]) { 
 
      return { 
 
       group: "/" + t + "/" + schools[t][i][0] + "/", 
 
       domain: schools[t][i][1], 
 
       schoolType: t 
 
      } 
 
     } 
 
     } 
 
    } 
 
    } 
 
} 
 

 
console.log(findData("Abernethy Primary")); 
 
console.log(findData("Wick High School"));

+0

對不起,但這是一個可怕的方式來做到這一點。是的,它會起作用,但是,如何將這個帖子作爲答案發布,而@ br3t已經提出的更深入更好的解決方案就是超越我的。沒有失望,因爲它會起作用,但這是唯一的原因。 – Archer

+0

@Archer它可能是可怕的,但它給了Op一些替代。 OP可以自由選擇哪一個。我的解決方案是減少字符,因爲它消除了學校名稱和學校類型的冗餘。當你必須手動輸入千位數字時,這太棒了。 –

+0

不,我們完全不同意。我認爲這是錯誤的,與更好的解決方案相比。這會以難以理解的方式分解數據,然後您必須搜索2個不相關的數組才能找到1條記錄,其中只有1條記錄。這種方法很難看,表現不好,而且更難以理解。這些都是非常重要的因素,當試圖創造一個好的解決方案,而不是一些剛剛起作用。 – Archer