以下是我如何在 listItemState 变量中获取下拉列表选择值:
+--------+---------------------+---------------------+
|UniqueID|start_time |stop_time |
+--------+---------------------+---------------------+
|u3 |2018-01-25 18:56:17.0|2018-01-31 07:48:48.0|
|u1 |2018-01-22 13:04:32.0|2018-01-25 20:51:43.0|
|u1 |2018-02-02 09:40:58.0|2018-02-05 14:03:27.0|
|u2 |2018-01-22 13:04:35.0|2018-01-25 18:55:08.0|
|u2 |2018-01-31 07:48:43.0|2018-02-02 09:41:01.0|
+--------+---------------------+---------------------+
如何将此值(从下拉列表中选择)传递到 State 列,该列是其他列表中的查阅列。
var stcode = document.getElementById("Projstcode");
var stcodetxt = stcode.options[stcode.selectedIndex].text;
var listItemState = stcodetxt;
答案 0 :(得分:0)
查找字段设置为查找ID,此Id值是下拉列表选项Id,请参阅下面的演示以获取所选选项的ID,然后将其设置为列表查找字段:
<script type="text/javascript" src="../SiteAssets/jquery.js"></script>
<script type="text/javascript">
function additemstolist()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('NewList');
var listItemInfo = new SP.ListItemCreationInformation();
var listItem = list.addItem(listItemInfo);
listItem.set_item('Title', 'My Test Title');
var countryvalue = new SP.FieldLookupValue();
countryvalue.set_lookupId($("select[title='myselect'] option:selected").attr("id"));
listItem.set_item('carlookup', countryvalue);
listItem.update();
context.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFailure));
}
function onSuccess() {
alert("Item Added Successfully.");
}
function onFailure() {
alert("Error Occured!!!");
}
</script>
<select title="myselect">
<option value="volvo" id="1">Volvo</option>
<option value="saab" id="2">Saab</option>
<option value="mercedes" id="3">Mercedes</option>
</select>
<input type='button' id='1234' value='Click Me' onclick="additemstolist();"/>