[英]SHAREPOINT 2013: How can I read Site column contents and modify them via javascript csom?
我對Sharepoint 2013相對較新,我試圖訪問頁面上的內容並顯示在特定的“站點列”中,我已經閱讀了很多有關此內容的內容,但仍然無法完成我的任務。 到目前為止,我明白了:
'use strict';
var hostweburl;
var appweburl;
$(function () {
SP.SOD.executeOrDelayUntilScriptLoaded(Function.createDelegate(this, function () {
var currentcontext = new SP.ClientContext.get_current();
var web = currentcontext.get_web();
//Get all fields in site collection
var collFields = web.get_availableFields().getByTitle("EngineType_EngineCycle");
currentcontext.load(collFields);
currentcontext.executeQueryAsync(Function.createDelegate(this, ExecuteOnSuccess),
Function.createDelegate(this, ExecuteOnFailure));
}), 'SP.js');
function ExecuteOnSuccess(sender, args)
{
var subsites = '';
//for(int i=0; i< collF {
// if(collFields[i].Title == "siteColumnName"){
// alert("Got the Site col");
// }
//}
}
function ExecuteOnFailure(sender, args) {
alert("error");
}
});
但是現在我不知道該如何訪問/檢索CollField內部所需的數據,也許我在某個地方出錯了? 請幫忙。 非常感謝。
SP.FieldCollection對象包含以下用於獲取Field對象的方法:
例
下面的示例演示如何檢索站點列:
function getSiteField(fieldName,success,failure)
{
var ctx = SP.ClientContext.get_current();
var rootWeb = ctx.get_site().get_rootWeb();
var field = rootWeb.get_availableFields().getByInternalNameOrTitle(fieldName);
ctx.load(field);
ctx.executeQueryAsync(
function(){
success(field)
},
failure);
}
用法
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function() {
//get Title column and print its properties
getSiteField('Title',
function(field){
//print field properties
console.log(field.get_title());
console.log(field.get_internalName());
console.log(field.get_typeAsString());
console.log(field.get_description());
},
function(sender,args){
console.log(args.get_message());
});
});
下面的示例演示如何更新SP.FieldChoice
字段屬性:
function updateFieldChoice(fieldTitle,choiceValues,success,failure) {
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var fieldChoice = ctx.castTo(web.get_availableFields().getByTitle(fieldTitle), SP.FieldChoice);
fieldChoice.set_choices(choiceValues);
fieldChoice.update();
ctx.executeQueryAsync(
function(){
success(fieldChoice)
},
failure);
}
用法
var choiceValues = ["Low", "Normal", "Critical"];
updateFieldChoice('RequestStatus',choiceValues,
function(field){
console.log('Choice field has been updated');
},
function(sender,args){
console.log(args.get_message());
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.