显示一个查询的结果,该查询将一个字段的总计计算为列表中标签的值
Display result of a query that calculates the total of a field as the value of a label in a list
我有两个数据源 tables 项目和 tt_records 带有小时数字段。项目与 tt_records 之间存在一对多关系。我想在 table 中显示每个项目的总小时数。我能够计算服务器端功能的总小时数,如何将总小时数与 UI 上的标签绑定。我正在尝试在该字段的绑定中使用以下内容。我看到该函数是通过控制台日志中的信息语句调用的,但是该值未显示在 UI clientgetProjHours(@datasource.item._key);以下是客户端脚本
function clientgetProjHours(key){
return (google.script.run.withSuccessHandler(function (key) {
console.info("received result");
}).getProjHours(key));
}
以下是服务器端脚本
function getProjHours(key){
console.log ("In the function getProjHours (" + key +")");
var pRecords = app.models.Projects.getRecord(key);
console.log("Contents of " + pRecords);
var tRecords =pRecords.tt_record;
console.log("Contents of t Records" + tRecords);
var total = 0;
tRecords.forEach (function (item){
total += item.actuals;
});
console.log ("The result is: " + total);
return total;
}
能否请您提出实现此功能的最佳方法。
非常感谢您的帮助
key
function (key) {
中的参数是服务器脚本的结果。
所以你只需要替换:
function (key) {
与:
function (result)
同时替换:
console.info("received result");
与:
app.pages.[PageName].descendants.[LabelName].text = result;
但正如它已经提到的那样 Calculated Model 应该更适合这种用例。
我有两个数据源 tables 项目和 tt_records 带有小时数字段。项目与 tt_records 之间存在一对多关系。我想在 table 中显示每个项目的总小时数。我能够计算服务器端功能的总小时数,如何将总小时数与 UI 上的标签绑定。我正在尝试在该字段的绑定中使用以下内容。我看到该函数是通过控制台日志中的信息语句调用的,但是该值未显示在 UI clientgetProjHours(@datasource.item._key);以下是客户端脚本
function clientgetProjHours(key){
return (google.script.run.withSuccessHandler(function (key) {
console.info("received result");
}).getProjHours(key));
}
以下是服务器端脚本
function getProjHours(key){
console.log ("In the function getProjHours (" + key +")");
var pRecords = app.models.Projects.getRecord(key);
console.log("Contents of " + pRecords);
var tRecords =pRecords.tt_record;
console.log("Contents of t Records" + tRecords);
var total = 0;
tRecords.forEach (function (item){
total += item.actuals;
});
console.log ("The result is: " + total);
return total;
}
能否请您提出实现此功能的最佳方法。 非常感谢您的帮助
key
function (key) {
中的参数是服务器脚本的结果。
所以你只需要替换:
function (key) {
与:
function (result)
同时替换:
console.info("received result");
与:
app.pages.[PageName].descendants.[LabelName].text = result;
但正如它已经提到的那样 Calculated Model 应该更适合这种用例。