selections

selections

使用范围: client

编程语言: javascript

父类: Item 类

描述说明

selections 属性存储主键字段值的列表。

当在 视图表单对话框布局 选项卡上选中 多选 复选框,或者以编程方式设置 table_options 的多选属性时,表格的最左侧列就会出现复选框,每次用户单击复选框时, selections 属性都会发生变化。

也可以通过使用 addremove 方法或分配数组以编程方式对其进行更改。

示例

在这个例子中,客户端上的 send_email 函数使用 Customers 的 selections 属性获取用户选择的主键字段值数组,并使用 server 方法将它们发送到实体项服务端模块中定义的 ``send_email``功能

function send_email(subject, message) {
    var selected = task.customers.selections;
    if (!selected.length) {
        selected.add(task.customers.id.value);
    }

    item.server('send_email', [selected, subject, message],
        function(result, err) {
            if (err) {
                item.alert('Failed to send the mail: ' + err);
            }
            else {
                item.alert('Successfully sent the mail');
            }
        }
    );
}

在服务端,使用 open 方法来检索已选择的客户的相关信息。

import smtplib

def send_email(item, selected, subject, mess):
    cust = item.task.customers.copy()
    cust.set_where(id__in=selected)
    cust.open()
    to = []
    for c in cust:
        to.append(c.email.value)

    # code that sends email