单击鼠标右键以更新列表列的文本的SharePoint传递值

问题描述 投票:0回答:1

我在一个SP页面上有一个文本框。单击提交按钮后,我需要将数值/输入发送到列表中的一列。我在网上找到了一些零碎的代码,但是没有用。

<table>
<tr>
<td>Shipping</td>
</tr>

<tr>
<td>Domestic:</td>
</tr>

<tr>
<td><input id="domesticshippinginput" name="domesticshippinginput" 
type="textbox" /></td>
<td><input name="ADD" id="btnADD" type="submit" value="Submit" /></td>
</tr>

</table>


<script language="javascript" type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(updateListItem,'sp.js'); 

function updateListItem() {
var clientContext = new SP.ClientContext.get_current();
var list = 
clientContext.get_web().get_lists().getByTitle('CurrentTimeFrame');
var domesticshipping = list.getItemById(1);
listItem.set_item('days', domesticshippinginput);
listItem.update();
clientContext.executeQueryAsync(Function.createDelegate(this, 
this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)
);
}

function onQuerySucceeded() {
alert('Item updated successfully!');
}

function onQueryFailed(sender, args) {
alert('Could not update item: ' + args.get_message());
}
</script>

其中CurrentTimeFrame是列表的名称,domesticshipping是该行的标题的名称,days是我需要写入的列表中的列。国内运输是列表中的第一项。所有代码均编码在同一代码段中(不确定是否重要)。

list sharepoint textbox sharepoint-2013
1个回答
0
投票

您可以使用rest api创建/更新SharePoint列表项。

通过jQuery获取输入值。demo thread

例如:

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
        function CreateItem() {
            $.ajax
                ({
                    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('TestList')/items",
                    type: "POST",
                    data: JSON.stringify
                        ({
                            __metadata:
                            {
                                type: "SP.Data.TestListListItem"
                            },
                            Title: $('#txtTitle').val()
                        }),
                    headers:
                    {
                        "Accept": "application/json;odata=verbose",
                        "Content-Type": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val()
                    },
                    success: function (data, status, xhr) {
                        window.location.href = _spPageContextInfo.webAbsoluteUrl + "/Lists/TestList/EditForm.aspx?ID=" + data.d.Id + ""
                    },
                    error: function (xhr, status, error) {
                        console.log(data.responseJSON.error);
                    }
                });
        }

    </script>
    <div>
        Title:
        <br />
        <input type="text" id="txtTitle" />
        <br />
        <input id="Button1" onclick="CreateItem()" type="button" value="button" />
    </div>
© www.soinside.com 2019 - 2024. All rights reserved.