Main Content

本页采用了机器翻译。点击此处可查看英文原文。

addAttribute

类: slreq.LinkSet
命名空间: slreq

向链接集添加自定义属性

自 R2020b 起

语法

addAttribute(myLinkSet,name,type)
addAttribute(myLinkSet,name,'Checkbox','DefaultValue',value)
addAttribute(myLinkSet,name,'Combobox','List',options)
addAttribute(myLinkSet,___,'Description',descr)

说明

addAttribute(myLinkSet,name,type) 将具有 name 指定的名称和 type 指定的自定义属性类型的自定义属性添加到链接集 myLinkSet

addAttribute(myLinkSet,name,'Checkbox','DefaultValue',value) 向链接集 myLinkSet 添加 Checkbox 自定义属性,其名称由 name 指定,默认值由 value 指定。

addAttribute(myLinkSet,name,'Combobox','List',options)name 指定名称的 Combobox 自定义属性,以及 options 指定的列表选项添加到链接集 myLinkSet

addAttribute(myLinkSet,___,'Description',descr) 向链接集 myLinkSet 添加一个自定义属性,其名称由 name 指定,类型由 type 指定,描述由 descr 指定。

输入参数

全部展开

链接集,指定为 slreq.LinkSet 对象。

自定义属性名称,指定为字符数组。

自定义属性类型,指定为字符数组。有效的自定义属性类型是 'Edit''Checkbox''Combobox''DateTime'

自定义属性描述,指定为字符数组。

Checkbox 默认值,指定为逻辑 1 (true)0 (false)

Combobox 列出选项,指定为元胞数组。仅当 'Unset' 是第一个条目时,选项列表才有效。'Unset' 表示用户尚未从组合框中选择选项。如果列表不是以 'Unset' 开头,它将自动附加为第一个条目。

示例: {'Unset','A','B','C'}

示例

全部展开

此示例显示如何向所有四种可用类型 EditCheckbox、Combobox 和 DateTime 添加自定义属性,以及如何添加带有描述的自定义属性。

加载crs_req_func_spec需求集。

rs = slreq.load("crs_req_func_spec");

获取 crs_req_func_spec 链接集的句柄。

ls = slreq.find(Type="LinkSet",Name="crs_req_func_spec");

添加 Edit 自定义属性

向链接集添加Edit自定义属性。使用 inspectAttribute 确认添加的属性。

addAttribute(ls,"MyEditAttribute","Edit");
atrb = inspectAttribute(ls,"MyEditAttribute")
atrb = struct with fields:
           name: "MyEditAttribute"
           type: Edit
    description: ''

添加 Checkbox 自定义属性

添加具有默认值 trueCheckbox 自定义属性。使用 inspectAttribute 确认属性已成功添加。

addAttribute(ls,"MyCheckbox","Checkbox","DefaultValue",true);
atrb2 = inspectAttribute(ls,"MyCheckbox")
atrb2 = struct with fields:
           name: "MyCheckbox"
           type: Checkbox
    description: ''
        default: 1

添加 Combobox 自定义属性

添加 ComboBox 自定义属性,其选项为 UnsetABC。使用 inspectAttribute 确认属性已成功添加。

addAttribute(ls,"MyCombobox","Combobox","List",["Unset","A","B","C"]);
atrb3 = inspectAttribute(ls,"MyCombobox")
atrb3 = struct with fields:
           name: "MyCombobox"
           type: Combobox
    description: ''
           list: {'Unset'  'A'  'B'  'C'}

添加 DateTime 自定义属性

添加DateTime自定义属性。使用 inspectAttribute 确认属性已成功添加。

addAttribute(ls,"MyDateTime","DateTime");
atrb4 = inspectAttribute(ls,"MyDateTime")
atrb4 = struct with fields:
           name: "MyDateTime"
           type: DateTime
    description: ''

添加带有说明的自定义属性

添加Edit自定义属性。为自定义属性添加描述。使用 inspectAttribute 确认属性已成功添加。

addAttribute(ls,"MyEditAttribute2","Edit","Description",...
    "You can enter text as the custom attribute value.");
atrb5 = inspectAttribute(ls,"MyEditAttribute2")
atrb5 = struct with fields:
           name: "MyEditAttribute2"
           type: Edit
    description: 'You can enter text as the custom attribute value.'

添加 ComboBox 自定义属性,其选项为 UnsetABC。为自定义属性添加描述。使用 inspectAttribute 确认属性已成功添加。

addAttribute(ls,"MyCombobox2","Combobox","List",["Unset","A","B","C"],"Description",...
    "This combo box attribute has 4 options.");
atrb6 = inspectAttribute(ls,"MyCombobox2")
atrb6 = struct with fields:
           name: "MyCombobox2"
           type: Combobox
    description: 'This combo box attribute has 4 options.'
           list: {'Unset'  'A'  'B'  'C'}

版本历史记录

在 R2020b 中推出