3
我对Sharepoint 2013相对比较陌生,我试图用数组内容更新网站列的内容,我可以检索并可视化我的网站列的内容,用户可以更改并保存必要的部分和更改被保存到一个数组中,现在我必须用数组的内容更新网站列的内容,但出于某种原因,我无法完成这些任何建议/示例?这是我的代码到目前为止检索,可视化站点列并将mofication存储到我的数组。SHAREPOINT 2013:如何使用javascript CSOM更新一个数组内容的网站列?
<body>
<select id="dropdown" name="dropdown" onchange="optSelect()">
<option value="EngineType_Cylinders">EngineType_Cylinders</option>
<option value="EngineType_EngineCycle">EngineType_EngineCycle</option>
<option value="EngineType_EngineFamily">EngineType_EngineFamily</option>
<option value="EngineType_Euro">EngineType_Euro</option>
<option value="EngineType_FamilyEvolution">EngineType_FamilyEvolution</option>
<option value="EngineType_GasEmissionLevel">EngineType_GasEmissionLevel</option>
<option value="EngineType_Power">EngineType_Power</option>
<option value="EngineType_PowerSupply">EngineType_PowerSupply</option>
<option value="EngineType_Use">EngineType_Use</option>
</select><br />
<textarea id="textareadisplay" rows="25" cols="23"></textarea><br />
<input type ="button" value="Update values" onclick="addItemsToColumns()" />
</body>
我的JavaScript
$(function() {
SP.SOD.executeOrDelayUntilScriptLoaded(Function.createDelegate(this, function() {
var select = document.getElementById('dropdown').value;
console.log(select);
getSiteColumns(select);
}), 'SP.js');
});
var fieldChoice;
var choices;
var addFields = [];
var slc;
var clientContext;
function optSelect() {
slc = document.getElementById('dropdown').value;
getSiteColumns(slc);
}
function getSiteColumns(selection) {
clientContext = SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var web = clientContext.get_web();
fieldChoice = clientContext.castTo(web.get_availableFields().getByTitle(selection), SP.FieldChoice);
clientContext.load(this.fieldChoice);
clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
}
}
function OnLoadSuccess(sender, args) {
choices = fieldChoice.get_choices();
var textarea = document.getElementById("textareadisplay");
textarea.value = choices.join("\n");
}
function OnLoadFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function addItemsToColumns() {
clientC = SP.ClientContext.get_current();
var arrayForUpdate = $('#textareadisplay').val().split('\n');
fieldChoice.set_item(, arrayForUpdate);
fieldChoice.update();
clientContext.executeQueryAsync(function() { }, function() { });
}
function OnUpdateSuccess(sender, args) {
var newchoices = fieldChoice.get_choices();
}
我的问题是关于函数addItemsToColumns(),请帮助!提前致谢。
好,我贴你的代码,我把函数“addItemsToColumns()”的onClick事件,但我的网站列仍然不能用新值更新..当我刷新页面时,网站栏目仍然存在旧的值..我正在努力工作,并让我疯狂。CONSOLE LOG SAYS:此功能对于与列表不相关的字段不可用。 – FabioEnne
啊,请用get_fields()替换函数get_availableFields(),我相信错误会消失(请参阅更新后的答案) –
完成它..但现在它不再显示我的站点列了...... :(...我开始失去对此的所有希望..... – FabioEnne