在App Maker中,如何制作动态表格单元格文本? [英] In App Maker, how do you make dynamic table cell text?

查看:74
本文介绍了在App Maker中,如何制作动态表格单元格文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在App Maker中,我正在显示一个表,并希望使用另一个表中的数据查找将表单元格数据替换为不同的文本.假设有两个表DepartmentsEmployees.

In App Maker, I am displaying a table and want to replace table cell data with different text using a data lookup from another table. Assume two tables, Departments and Employees.

  • Departments是两个字段,DeptID和DeptDescription.
  • Employees是包括DeptID在内的多个字段.
  • Departments is two fields, DeptID and DeptDescription.
  • Employees is multiple fields including DeptID.

Employees的表列表中,我想将DeptID替换为DeptDescription. (页面数据源是Employees.我不想在数据模型之间建立关系.)

In the table listing for Employees, I would like to replace the DeptID with the DeptDescription. (The page datasource is Employees. I do not want to set up a relationship between the data models.)

我猜想我想在onDataLoad事件中为DeptID的表格单元格标签编写一些脚本.到目前为止,我有这么多:

I am guessing I want to do some scripting in the onDataLoad event for the table cell label for DeptID. I have this much so far:

 app.datasources.Departments.query.filters.DeptID._equals = widget.datasource.item.DeptID;
 app.datasources.Departments.newQuery().run();
 widget.text = app.datasources.Departments.item.DeptDescription;

我知道这是不正确的,但是我要关闭吗?

I know this is not correct, but am I close?

推荐答案

该答案未经测试,但是我想提出一个可能的解决方案,该解决方案不需要大量的DB调用,尤其是那些重复调用服务器脚本的调用当您进行订单项调用时,这可能会花费大量的处理时间.

This answer is untested, but I wanted to present a possible solution that would not require a lot of DB calls, especially ones that make repeated calls to a server script which might consume a lot of processing time when you do line item calls.

  1. 在Department模式下设置单独的数据源.将默认的查询生成器"更改为查询脚本",并添加类型为列表(数字)"或列表(字符串)"的参数,这应与您的主键字段类型匹配.取消选中自动加载"选项.
  2. 在查询脚本"部分中,输入以下代码:

  1. Set up a separate datasource under the Department model. Change the default 'Query Builder' to 'Query Script' and add a parameter of type 'list(number)' or 'list(string)', this should match your Primary Key field type. Uncheck the 'auto load' option.
  2. In your 'Query Script' portion enter the following code:

query.filters.Id._in = query.parameters.YourParameter;

query.filters.Id._in = query.parameters.YourParameter;

返回query.run();

return query.run();

转到应该生成表的雇员"数据源,然后找到加载时"客户端脚本部分.在此部分中,输入以下代码:

Go to your Employees datasource that is supposed to generate your table and find your 'On Load' client script section. In this section enter the following code:

var departmentDs = app.datasources.YourDepartmentsDs;

var departmentsDs = app.datasources.YourDepartmentsDs;

departmentsDs.properties.YourParameter = datasource.items.map(function(deptIds){return deptIds.DeptID;});

departmentsDs.properties.YourParameter = datasource.items.map(function(deptIds) {return deptIds.DeptID;});

departmentDs.load();

departmentDs.load();

现在转到包含表的页面.如果尚未创建标签小部件,请立即创建.在用于文本绑定的此标签小部件中,输入以下内容:

Now go the page that contains your table. If you have not already create a label widget do so now. In this label widget for the text binding enter the following:

@ datasources.YourDepartmentsDs.loaded&& (@ datasources.YourDepartmentsDs.items).map(function(Id){return Id.Id}).indexOf(@ widget.datasource.item.DeptID)!== -1吗? @ datasources.YourDepartmentDs.items [(@ datasources.YourDepartmentsDs.items).map(function(Id){return Id.Id}).indexOf(@ widget.datasource.item.DeptID)].DeptDescription:'无法检索部门说明"

@datasources.YourDepartmentsDs.loaded && (@datasources.YourDepartmentsDs.items).map(function(Id){return Id.Id}).indexOf(@widget.datasource.item.DeptID) !== -1 ? @datasources.YourDepartmentDs.items[(@datasources.YourDepartmentsDs.items).map(function(Id){return Id.Id}).indexOf(@widget.datasource.item.DeptID)].DeptDescription : 'Unable to retrieve Dept Description'

如上所述,这未经测试,我在没有App Maker的情况下从内存中编写了代码,因此可能需要进行一些其他调整.遵循J.G.提出的第一个选项但这也是一个非常可行的解决方案.我很抱歉,但是代码格式化程序似乎对我不起作用.

As stated this is untested and I wrote the code from memory without App Maker in front of me so it may require some additional tweaking. Going with the first option presented by J.G. would also be a very viable solution though. And I apologize but the code formatter does not seem to be working for me.

这篇关于在App Maker中,如何制作动态表格单元格文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆