私は何かを最適化しようとしています。私のスクリプト:
function d1() {
for (i = 0; i < 1; i++) {
d1();
}
Logger.log("DONE!");
}
function d2() {
for (i = 1; i < 2; i++)
Logger.log("IN PROGRESS...");
}
このスクリプトは決して完了しません! しかし、私がに変更した場合
function d1() {
for (i = 0; i < 1; i++) {
for (i = 1; i < 2; i++)
Logger.log("IN PROGRESS...");
}
Logger.log("DONE!");
}
すべて完璧!私の問題は何ですか?
ああ、私は愚かです。もちろん、d2() を呼び出します。
私のスクリプトはまったく異なります。単純化しようとしましたが、元のファイルを送ったほうがよいと思います。明確になることを願っています。
プロジェクト.gs
function ViewNewProjects() {
var app = UiApp.getActiveApplication();
var wait = app.getElementById("wait");
wait.setStyleAttribute("display","none");
var spreadsheet = SpreadsheetApp.openById("0AnYzxNSJL2u_dDVETm9JNVAxQ3BESmdoNGZnc1JDN2c");
var sheet = spreadsheet.getSheetByName("Заявки Технического Отдела");
var data = app.getElementById("Data_Panel");
var range = sheet.getDataRange();
var values = range.getValues();
var bg = true;
data.clear();
for (i=2; i<values.length; i++) {
var row = app.createHorizontalPanel();
var techSpec = app.createHTML(values[i][4]);
var status = app.createHTML(values[i][11]);
if (values[i][4].length == 0 && values[i][12] != "Закрыт") {
var projectLabel = app.createHTML(values[i][0] + ", " + values[i][2]);
var typeLabel = app.createHTML(values[i][1]);
var postLabel = app.createHTML(values[i][5]);
var startDateLabel = app.createHTML(values[i][6]);
**var expDateLabel = app.createHTML(EstimateData(values[i][7]));**
var buttonGet = app.createButton("Взять проект");
var getProject = app.createServerHandler("ViewProject");
var ShowWait = app.createServerHandler("ShowWait");
projectLabel.setId("project_id_" + i);
projectLabel.addClickHandler(ShowWait);
projectLabel.addClickHandler(getProject);
row.setWidth("100%");
projectLabel.setStyleAttribute("margin", "3");
projectLabel.setStyleAttribute("padding", "10px");
typeLabel.setStyleAttribute("margin", "3");
typeLabel.setStyleAttribute("padding", "10px");
postLabel.setStyleAttribute("margin", "3");
postLabel.setStyleAttribute("padding", "10px");
startDateLabel.setStyleAttribute("margin", "3");
startDateLabel.setStyleAttribute("padding", "10px");
expDateLabel.setStyleAttribute("margin", "3");
expDateLabel.setStyleAttribute("padding", "10px");
if (bg == true) {
projectLabel.setStyleAttribute("background-color", "#e9e9e9");
typeLabel.setStyleAttribute("background-color", "#e9e9e9");
postLabel.setStyleAttribute("background-color", "#e9e9e9");
startDateLabel.setStyleAttribute("background-color", "#e9e9e9");
expDateLabel.setStyleAttribute("background-color", "#e9e9e9");
bg = false;
} else {
projectLabel.setStyleAttribute("background-color", "#f9f9f9");
typeLabel.setStyleAttribute("background-color", "#f9f9f9");
postLabel.setStyleAttribute("background-color", "#f9f9f9");
startDateLabel.setStyleAttribute("background-color", "#f9f9f9");
expDateLabel.setStyleAttribute("background-color", "#f9f9f9");
bg = true;
}
projectLabel.setStyleAttribute("cursor", "pointer");
projectLabel.setStyleAttribute("color", "blue");
projectLabel.setStyleAttribute("text-decoration", "underline");
row.add(projectLabel)
.add(typeLabel)
.add(postLabel)
.add(startDateLabel)
.add(expDateLabel)
.add(buttonGet);
row.setCellHorizontalAlignment(projectLabel, UiApp.HorizontalAlignment.LEFT);
row.setCellVerticalAlignment(projectLabel, UiApp.VerticalAlignment.MIDDLE);
row.setCellWidth(projectLabel, "320px");
row.setCellHorizontalAlignment(typeLabel, UiApp.HorizontalAlignment.CENTER);
row.setCellVerticalAlignment(typeLabel, UiApp.VerticalAlignment.MIDDLE);
row.setCellWidth(typeLabel, "120px");
row.setCellHorizontalAlignment(postLabel, UiApp.HorizontalAlignment.CENTER);
row.setCellVerticalAlignment(postLabel, UiApp.VerticalAlignment.MIDDLE);
row.setCellWidth(postLabel, "200px");
row.setCellHorizontalAlignment(startDateLabel, UiApp.HorizontalAlignment.CENTER);
row.setCellVerticalAlignment(startDateLabel, UiApp.VerticalAlignment.MIDDLE);
row.setCellWidth(startDateLabel, "80px");
row.setCellHorizontalAlignment(expDateLabel, UiApp.HorizontalAlignment.CENTER);
row.setCellVerticalAlignment(expDateLabel, UiApp.VerticalAlignment.MIDDLE);
row.setCellWidth(expDateLabel, "80px");
row.setCellHorizontalAlignment(buttonGet, UiApp.HorizontalAlignment.CENTER);
row.setCellVerticalAlignment(buttonGet, UiApp.VerticalAlignment.MIDDLE);
data.add(row);
}
}
return app;
};
休日.gs
function EstimateData(date_to_estimate) {
var date = new Date();
var count = 0;
var mounth = new String(date.getMonth() + 1);
var day = new String(date.getDate());
var year = new String(date.getFullYear());
if (mounth < 10)
mounth = new String("0" + mounth);
var current_date = year + mounth + day;
var ___date_to_estimate = new String(date_to_estimate);
var date_to_estimate_array = ___date_to_estimate.match(/(\d+)\.(\d+)\.(\d+)/);
var ___date_to_estimate = date_to_estimate_array[3] + date_to_estimate_array[2] + date_to_estimate_array[1];
current_date = Number(current_date);
___date_to_estimate = Number(___date_to_estimate);
if (current_date > ___date_to_estimate) {
Logger.log("Текущая дата больше рассчитываемой");
var difference = Number(current_date - ___date_to_estimate);
Logger.log("Разница " + difference);
if (difference == 0) {
return date_to_estimate;
} else if (difference < 31) {
var weekday = date.getDay();
Logger.log("День недели " + weekday);
for (i = 1; i < difference; i++) {
if (weekday == 7)
weekday = 0;
if (weekday > 0 && weekday < 6) {
count++;
}
weekday++;
}
} else if (difference < 1130) {
} else {
}
} else if (current_date == ___date_to_estimate) {
date_to_estimate = '<b>Сегодня!!!</b>';
} else {
}
Logger.log("Количество рабочих дней " + count);
return date_to_estimate;
}
メッセージを書いてテストしているときに、間違いを見つけました。
project.gs のループには変数 i が含まれています。holadays.gs のループには変数 i も含まれています。
変数を変更しましたが、大丈夫です!