如何重新执行 App Maker 数据源的查询脚本
How to re-execute the query script of an App Maker Datasource
目标
使用应用制作工具收集用户生日并仅显示本月的生日。
问题
我有一个数据模型,persons
。在该模型中有两个数据源,默认的 persons
和第二个 birthdaysThisMonth
。 birthdaysThisMonth
中的数据源查询脚本正常运行,并且 returns 只有本月来自 persons
模型的生日。
但是,当我更改 persons
数据源中的生日时,birthdaysThisMonth
数据源保持不变,例如,birthdaysThisMonth
中的查询脚本不是 re -执行.
要更改生日,我 select 从日期选择器中输入一个新日期,新值显示在 table 中。我没有使用提交按钮,当日期选择器失去焦点时我看到了变化。
我试过的
此脚本在 birthdaysThisMonth
数据源 中作为 查询脚本 执行, 未设置 至 Manual save mode
。它returns我想要的记录。
function setBirthdays() {
var calcRecords = [];
var personsRecords = app.models.persons.newQuery().run();
for (i=0; i<personsRecords.length; i++) {
var id = app.models.persons.newQuery().filters.Id._equals = i;
if (personsRecords[i].birthdate.getMonth() == thisMonth()) {
var calcRecord = app.models.persons.newRecord();
calcRecord.emailSecondary = personsRecords[i].emailSecondary;
calcRecord.birthdate = personsRecords[I].birthdate;
calcRecord.Id = personsRecords[i].Id;
calcRecords.push(calcRecord);
}
}
return calcRecords;
}
问题
如何在persons
中的数据更新后重新执行birthdaysThisMonth
中的查询脚本。我如何触发查询,以便它重新评估 persons
中的数据并相应地进行过滤。
使用事件和 onAfterSave
似乎很有前途,但我还没有找到这样的例子。
顺便说一句
如果可能的话,我希望这项工作在服务器端进行。
请参阅 Markus Malessa 的评论以获得答案。
Unfortunately you can't use server events like onAfterSave to trigger reloading a datasource on the client, so your proposed solution won't work. It would seem that your only possible solution would be to make your persons datasource a manual save datasource, in the form where you change the birth date you will need a 'Save' button that calls widget.datasource.saveChanges() and in that function incorporate a callback that will reload your birthdaysThisMonth datasource
我尝试 push/pull 数据的方式不是很好。看起来手动模式提供了我需要的功能类型。
目标
使用应用制作工具收集用户生日并仅显示本月的生日。
问题
我有一个数据模型,persons
。在该模型中有两个数据源,默认的 persons
和第二个 birthdaysThisMonth
。 birthdaysThisMonth
中的数据源查询脚本正常运行,并且 returns 只有本月来自 persons
模型的生日。
但是,当我更改 persons
数据源中的生日时,birthdaysThisMonth
数据源保持不变,例如,birthdaysThisMonth
中的查询脚本不是 re -执行.
要更改生日,我 select 从日期选择器中输入一个新日期,新值显示在 table 中。我没有使用提交按钮,当日期选择器失去焦点时我看到了变化。
我试过的
此脚本在 birthdaysThisMonth
数据源 中作为 查询脚本 执行, 未设置 至 Manual save mode
。它returns我想要的记录。
function setBirthdays() {
var calcRecords = [];
var personsRecords = app.models.persons.newQuery().run();
for (i=0; i<personsRecords.length; i++) {
var id = app.models.persons.newQuery().filters.Id._equals = i;
if (personsRecords[i].birthdate.getMonth() == thisMonth()) {
var calcRecord = app.models.persons.newRecord();
calcRecord.emailSecondary = personsRecords[i].emailSecondary;
calcRecord.birthdate = personsRecords[I].birthdate;
calcRecord.Id = personsRecords[i].Id;
calcRecords.push(calcRecord);
}
}
return calcRecords;
}
问题
如何在persons
中的数据更新后重新执行birthdaysThisMonth
中的查询脚本。我如何触发查询,以便它重新评估 persons
中的数据并相应地进行过滤。
使用事件和 onAfterSave
似乎很有前途,但我还没有找到这样的例子。
顺便说一句
如果可能的话,我希望这项工作在服务器端进行。
请参阅 Markus Malessa 的评论以获得答案。
Unfortunately you can't use server events like onAfterSave to trigger reloading a datasource on the client, so your proposed solution won't work. It would seem that your only possible solution would be to make your persons datasource a manual save datasource, in the form where you change the birth date you will need a 'Save' button that calls widget.datasource.saveChanges() and in that function incorporate a callback that will reload your birthdaysThisMonth datasource
我尝试 push/pull 数据的方式不是很好。看起来手动模式提供了我需要的功能类型。