2017-08-28 172 views
0

我有这个脚本,它完美的作品 - 如果“Y”是写在B94作为片1谷歌脚本 - 一个运行上编辑脚本多张

function runOnEdit(e){ 
var sheets = ["Sheet 1", "Sheet 2"]; // change sheet names to suit. 
var ind = sheets.indexOf(e.source.getActiveSheet().getName()); 
if(ind == -1 || e.range.getA1Notation() !== "B94" && e.range.getA1Notation() !== "B54" || e.value.toLowerCase() !== "y") return; 
ind == 0 ? Script1() : Script2(); 
} 

,它触发脚本1.如果它是写在表2 B54,它触发脚本2.

我想更多的床单和多个脚本把它添加。

function runOnEdit(e){ 
var sheets = ["HAR 2 Yelo", "HAR 2 Bambello", "HAR 2 KM5512"]; // change sheet names to suit. 
var ind = sheets.indexOf(e.source.getActiveSheet().getName()); 
if(ind == -1 || e.range.getA1Notation() !== "B94" && e.range.getA1Notation() !== "B54"&& e.range.getA1Notation() !== "B54" || e.value.toLowerCase() !== "y") return; 
ind == 0 ? CopyYeloPlants() : CopyBambelloPlants() : CopyKM5512Plants() ; 
} 

这是行不通的。我错过了什么?

回答

1

你的第二个脚本不再是继三元或有条件的运营商,这是

变量==条件的正确语法?值1:VALUE2

为了测试几个条件的语法将是例如:

可变==条件1? value1:variable == condition2? value2:变量== condition3? value3:value4;

或者在你的榜样:

变量==条件1? doThis():variable == condition2? doThat():variable == condition3? doSomehingElse():return;

来吧,试试这个工作的例子。为了可读性,我现在开始为每一条新线提供条件。

function answerTheQuestion() { 
//Hint: Correct answer is "A" 
var yourAnswer = "A"; //Fill in your answer here and run the script; 
yourAnswer == "C" ? Logger.log("Wrong answer!") : 
yourAnswer == "B" ? Logger.log("Try again") : 
yourAnswer == "A" ? Logger.log("That's right!") : 
Logger.log("3 strikes and your out") 
}