跳到主要内容

SetValue

设置表示组合框/下拉列表内容控件列表项值的字符串。

语法

expression.SetValue(sValue);

expression - 表示 ApiContentControlListEntry 类的变量。

参数

名称必需/可选数据类型默认值描述
sValue必需string列表项的值。

返回值

boolean

示例

为文档中的下拉列表或组合框列表条目分配新的底层值。

// How do I change the stored value of a list item in a document?

// Update the programmatic value of an entry independently of its display label in a document.

let doc = Api.GetDocument();
let cc = Api.CreateComboBoxContentControl([{display: "Mercury", value: "planet1"}, {display: "Venus", value: "planet2"}, {display: "Earth", value: "planet3"}, {display: "Mars", value: "planet4"}]);
let paragraph = doc.GetElement(0);
let contentControlList = cc.GetDropdownList();
paragraph.Push(cc);
let listItem = contentControlList.GetItem(2);
listItem.SetValue("Home");
listItem.Select();
paragraph = Api.CreateParagraph();
paragraph.AddText("Value of third item in list: " + listItem.GetValue());
doc.AddElement(0, paragraph);