...问题是最后一个函数通过google UI传递给它的事件知道选择的课程,但它不知道选择的等级。
Sample Data:
Grade Semester Course Unit
1 1 Chemistry101 Chemistry
3 2 Physics321 Physics
2 1 Chemistry101 Chemistry
function executionStartsHere() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('Course Planner');
var panel = app.createVerticalPanel();
panel.setId("main-panel");
//grades
panel.add(_getLabel("Grades"));
uniqueGrades = _findUniqueGrades();
gradeListBox = _getListBox(app,uniqueGrades,"grade-listbox","grades");
var gradeHandler = app.createServerHandler('_clickGrade');
gradeListBox.addChangeHandler(gradeHandler);
panel.add(gradeListBox);
//courses
panel.add(_getLabel("Courses"));
courseListBox = _getListBox(app,{},"course-listbox","courses");
var courseHandler = app.createServerHandler('_clickCourse');
courseListBox.addChangeHandler(courseHandler);
panel.add(courseListBox);
//semester
panel.add(_getLabel("Semester"));
semesterListBox = _getListBox(app,{},"semester-listbox","semesters");
panel.add(semesterListBox);
h = app.createHidden("selectedGrade").setId("selectedGrade");
h.setValue("1");
panel.add(h);
//finally
app.add(panel);
doc.show(app);
}
function _clickGrade(eventInfo) {
var app = UiApp.getActiveApplication();
// get value of ListBox based on name
var selectedGrade = eventInfo.parameter.grades;
Logger.log("In clickGrade, selected:"+selectedGrade);
//eventInfo.parameter.selectedGrade=selectedGrade;
app.getElementById("selectedGrade").setValue(selectedGrade);
Logger.log("eventInfo.parameter.selectedGrade: "+eventInfo.parameter.selectedGrade);
_displayCourses(selectedGrade);
return app;
}
function _clickCourse(eventInfo) {
//WE NEED TO SOMEHOW PASS THE SELCTED GRADE IN HERE
var app = UiApp.getActiveApplication();
var grade = app.getElementById("selectedGrade")
var grade2 = eventInfo.parameter.selectedGrade;
var course = eventInfo.parameter.courses;
Logger.log("Selected grade, grade2, course: "+grade+" ,"+grade2+" ,"+course);
_displaySemesters(grade,course);
return app;
}
function _displayCourses(grade) {
var app = UiApp.getActiveApplication();
validCourses = _findValidCourses(grade);
lb = app.getElementById("course-listbox");
_populateListBox(lb,validCourses);
}
function _displaySemesters(grade,course){
var app = UiApp.getActiveApplication();
validSemesters = _findValidSemesters(grade,course);
lb = app.getElementById("semester-listbox");
_populateListBox(lb,validSemesters);
}
function _findUniqueGrades(){
var workBook = _getWorkBook();
var sheet = _getLearningOutcomeSheet(workBook);
var graderows = getColumnAsArray(sheet, 1);
var grades= {};
for(var i=1; i<graderows.length; i++) { //skip the first row (labels)
if(graderows[i] != "" && graderows[i] != undefined ) {
grades[graderows[i]]=graderows[i];
}
}
return grades;
}
function _findValidCourses(grade) {
var workBook = _getWorkBook();
var sheet = _getLearningOutcomeSheet(workBook);
var graderows = getColumnAsArray(sheet, 1);
var courserows = getColumnAsArray(sheet, 3);
// loop over courserows
// if the grade for this courserow matches the grade we are searching for
// then store this courserow in an associative array
validCourses = {};
for(var i=0; i< courserows.length; i++) {
if ( graderows[i] == grade ) {
validCourses[courserows[i]] = courserows[i];
}
}
return validCourses;
}
function _findValidSemesters(grade,course){
var workBook = _getWorkBook();
var sheet = _getLearningOutcomeSheet(workBook);
var graderows = getColumnAsArray(sheet, 1);
var courserows = getColumnAsArray(sheet, 3);
var semesterrows = getColumnAsArray(sheet, 2);
validSemesters = {};
for(var i=0; i< semesterrows.length; i++){
if ( courserows[i] == course && graderows[i] == grade ){
validSemesters[semesterrows[i]] = semesterrows[i];
}
}
return validSemesters;
}
function _getListBox(app,items,id,label){
var lb = app.createListBox().setId(id).setName(label);
lb.setVisibleItemCount(1);
//add items, if any
for each ( i in items) {
lb.addItem(i);
}
return lb;
}
function _populateListBox(listBox,items){
listBox.clear();
Logger.log("ListBox ID: "+ listBox.getId());
for each ( i in items) {
Logger.log("adding item: " + i);
listBox.addItem(i);
}
}
function _getWorkBook(){
return SpreadsheetApp.openById(employee_SPREADSHEET);
}
function _getLearningOutcomeSheet(workBook){
return workBook.getSheets()[0];
}
function _getLabel(string){
var app = UiApp.getActiveApplication();
return app.createLabel(string);
}
function getColumnAsArray(sheet,column) {
var dataRange = sheet.getRange(1,column,99,1);
var data = dataRange.getValues()
//Logger.log("column values: " + data);
return data;
}
我想你只是忘了给隐藏的小部件设置一个名字,你只给了一个ID...正如您显然知道的,事件参数使用小部件的名称来取回它的值。:-)
h = app.createHidden("selectedGrade").setId("selectedGrade").setName("selectedGrade");
编辑:
哦,你说得对,我一开始没注意到。
function executionStartsHere() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('Course Planner');
var panel = app.createVerticalPanel();
panel.setId("main-panel");
//grades
panel.add(_getLabel("Grades"));
uniqueGrades = _findUniqueGrades();
gradeListBox = _getListBox(app,uniqueGrades,"grade-listbox","grades");
var gradeHandler = app.createServerHandler('_clickGrade').addCallbackElement(panel);
gradeListBox.addChangeHandler(gradeHandler);
panel.add(gradeListBox);
//courses
panel.add(_getLabel("Courses"));
courseListBox = _getListBox(app,{item:'First choose a grade value'},"course-listbox","courses");
var courseHandler = app.createServerHandler('_clickCourse').addCallbackElement(panel);
courseListBox.addChangeHandler(courseHandler);
panel.add(courseListBox);
//semester
panel.add(_getLabel("Semester"));
semesterListBox = _getListBox(app,{item:'First choose a course value'},"semester-listbox","semesters");
panel.add(semesterListBox);
var h = app.createTextBox().setName("selectedGrade").setId("selectedGrade");
var h2 = app.createTextBox().setName("selectedCourse").setId("selectedCourse");
panel.add(h).add(h2);
//finally
app.add(panel);
doc.show(app);
}
function _clickGrade(eventInfo) {
var app = UiApp.getActiveApplication();
// get value of ListBox based on name
var selectedGrade = eventInfo.parameter.grades;
Logger.log("In clickGrade, selected:"+selectedGrade);
//eventInfo.parameter.selectedGrade=selectedGrade;
app.getElementById("selectedGrade").setValue(selectedGrade);
Logger.log("eventInfo.parameter.selectedGrade: "+eventInfo.parameter.selectedGrade);
_displayCourses(selectedGrade);
return app;
}
function _clickCourse(eventInfo) {
//WE NEED TO SOMEHOW PASS THE SELCTED GRADE IN HERE
var app = UiApp.getActiveApplication();
var grade = app.getElementById("selectedGrade")
var grade2 = eventInfo.parameter.selectedGrade;
var course = eventInfo.parameter.courses;
app.getElementById("selectedCourse").setValue(course);
Logger.log("Selected grade, grade2, course: "+grade+" ,"+grade2+" ,"+course);
_displaySemesters(grade2,course);
return app;
}
function _displayCourses(grade) {
var app = UiApp.getActiveApplication();
validCourses = _findValidCourses(grade);
lb = app.getElementById("course-listbox");
_populateListBox(lb,validCourses);
}
function _displaySemesters(grade,course){
var app = UiApp.getActiveApplication();
Logger.log(grade+' '+course)
validSemesters = _findValidSemesters(grade,course);
lb = app.getElementById("semester-listbox");
_populateListBox(lb,validSemesters);
}
function _findUniqueGrades(){
var workBook = _getWorkBook();
var sheet = _getLearningOutcomeSheet(workBook);
var graderows = getColumnAsArray(sheet, 1);
var grades= {};
for(var i=1; i<graderows.length; i++) { //skip the first row (labels)
if(graderows[i] != "" && graderows[i] != undefined ) {
grades[graderows[i]]=graderows[i];
}
}
return grades;
}
function _findValidCourses(grade) {
var workBook = _getWorkBook();
var sheet = _getLearningOutcomeSheet(workBook);
var graderows = getColumnAsArray(sheet, 1);
var courserows = getColumnAsArray(sheet, 3);
// loop over courserows
// if the grade for this courserow matches the grade we are searching for
// then store this courserow in an associative array
validCourses = {};
for(var i=0; i< courserows.length; i++) {
if ( graderows[i] == grade ) {
validCourses[courserows[i]] = courserows[i];
}
}
return validCourses;
}
function _findValidSemesters(grade,course){
var workBook = _getWorkBook();
var sheet = _getLearningOutcomeSheet(workBook);
var graderows = getColumnAsArray(sheet, 1);
var courserows = getColumnAsArray(sheet, 3);
var semesterrows = getColumnAsArray(sheet, 2);
validSemesters = {};
for(var i=0; i< semesterrows.length; i++){
if ( courserows[i] == course && graderows[i] == grade ){
validSemesters[semesterrows[i]] = semesterrows[i];
}
}
return validSemesters;
}
function _getListBox(app,items,id,label){
var lb = app.createListBox().setId(id).setName(label);
lb.setVisibleItemCount(1);
//add items, if any
for each ( i in items) {
lb.addItem(i);
}
return lb;
}
function _populateListBox(listBox,items){
listBox.clear();
Logger.log("ListBox ID: "+ listBox.getId());
for each ( i in items) {
Logger.log("adding item: " + i);
listBox.addItem(i);
}
}
function _getWorkBook(){
return SpreadsheetApp.getActiveSpreadsheet()
}
function _getLearningOutcomeSheet(workBook){
return workBook.getSheets()[0];
}
function _getLabel(string){
var app = UiApp.getActiveApplication();
return app.createLabel(string);
}
function getColumnAsArray(sheet,column) {
var dataRange = sheet.getRange(1,column,99,1);
var data = dataRange.getValues()
//Logger.log("column values: " + data);
return data;
}
问题内容: 我有一个表,其中包含商店中每件商品的单价和其他详细信息。 另一个包含每个订单中包含的项目的详细信息。 现在我要计算 请注意,我希望它成为表本身的一部分,而不是作为其他视图或查询。我怎样才能做到这一点?我为此研究了触发器和其他机制,但是它们是否适用于不同表中的值,尤其是在存在此类约束的情况下? 我尝试过根据另一列计算出的Column进行以下触发吗?: 但这似乎没有用 问题答案: 这是如何
我肯定这是一个愚蠢的问题,但我找不到一个简单的方法将一个列表按另一个列表分组。我在网上搜索了很多,但我只找到了带有类属性或排序元素的示例。 我有一个带有键的字符串列表,例如: 和一个我想按键列表分组的int列表,例如: 因此结果应该是一个包含子列表的列表,如下所示: 或者也可以得到指数。提前道谢。
我在从一个表中插入一个列的值作为另一个表中的列时遇到了麻烦。我在col1中有一些值的表A:和另一个列等于col1值的表B。 我想把表A,col1中的其余值添加为表B中的列。请帮助我解决我的问题。我正在使用SQL server 2012。
问题内容: 我不太明白为什么我不能将Int []从一个函数传递到另一个函数: 这给了我以下错误: 谢谢你的帮助! 问题答案: 中的参数称为 可变参数 。这意味着您可以传入该参数类型的可变数量,并且传入的所有内容都将转换为该类型的数组,以供您在函数中使用。 因此,内部的参数是一个数组,而不是所期望的一组参数。 您可能想要像这样重载以接受其中任何一个,因此您的平均函数可以调用适当的版本:
问题内容: 我有2个表,一个包含我需要的最终结果,另一个包含我需要根据设定级别选择的列列表。 例如 : 所以,如果我做以下 然后,基本上我需要使用此select语句中的列名来确定从另一条语句中选择了哪些列。 香港专业教育学院尝试过的方法,我当然知道这是错的,但可以让我对我试图做的事情有所了解。 我试图以一种动态方式构建一个sql查询,该查询可以通过我放在表中的任何列进行更改。 从理论上讲,这应与以
我有一张地图,用户可以在其中选择一个县。我希望它能够做的是返回“成员”在该县的所有“遭遇”。 唯一的问题是,“county”不是我需要为其返回文档的索引字段(“county”是“member”索引中的字段,而我想从“Conferences”索引中返回文档)(它们由“memberId”链接)。 以下是我目前所做的,在一个县中获得成员。 但这将返回该县成员的文档列表。我需要它返回这些文档的member