Sharepoint 2013:站点列的 CRUD 操作

Sharepoint 2013: CRUD operations on Site Columns

到目前为止,我能够对列表执行 CRUD 操作,我想知道是否可以在网站栏上执行此操作,我试图在网络上找到它,但我确实一无所获,我致力于在这里提出一个问题只是为了了解是否可能,如果有可能请任何人给我提供一些资源以便我学习?提前致谢。

在 MSDN 站点上,您可以找到有关 CSOM 的有用信息:

How to: Complete basic operations using JavaScript library code in SharePoint 2013 How to: Complete basic operations using JavaScript library code in SharePoint 2013

而在第二个 link 你可以找到关于 CRUD operation on Lists

的线索

如果要对站点栏的设置进行操作,可以参考MSDN FieldCollection methods

还有 javascript 的等效命名空间。

基本上您可以使用 AddFieldAsXml, you can Update/Delete using method GetByID (or Title or InternalName) and perform operation on returned Field 添加网站栏。

这正是您所需要的,几周前我已经为工作完成了。

var ctx;
        var web;
        var fieldChoice;
        var fieldName;
        var values;

        $(function () {
            SP.SOD.executeOrDelayUntilScriptLoaded(Function.createDelegate(this, function () {
                fieldName = $('#dropdown').find(":selected").text();
                populateValues(fieldName);
            }), 'SP.js');
        });

        function selection() {
            fieldName = $('#dropdown').find(":selected").text();
            populateValues(fieldName);
        }

        function populateValues(fieldName) {
            ctx = SP.ClientContext.get_current();
            web = ctx.get_web();
            fieldChoice = ctx.castTo(web.get_availableFields().getByTitle(fieldName), SP.FieldChoice);
            ctx.load(this.fieldChoice);
            ctx.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
        }
        /* Displays the vaules of the array in the textarea */
        function OnLoadSuccess() {
            values = fieldChoice.get_choices();
            $("textarea#textareadisplay").val(values.join("\n"));

        }

        function OnLoadFailed(e, args) {
            alert();
        }

        /* Push the textarea values in an array */
        function addItemsToColumns() {
            values = $('textarea#textareadisplay').val().split('\n');
            columnSpaceDelete();
            updateFieldChoice();
        }

        /* Function to delete empty values in the array */
        function columnSpaceDelete() {
            for (x = 0; x <= values.length - 1; x++) {
                var a = values.indexOf("");
                if (a !== -1) {
                    values.splice(a, 1);
                }
            }
        }

        /* Update the columns values whit the values in the array */
        function updateFieldChoice() {
            fieldChoice.set_choices(values);
            fieldChoice.update();
            ctx.executeQueryAsync(function () { }, function () { });
        }

相对HTML:

<select id="dropdown" name="dropdown" onchange="selection()">
            <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"></textarea><br />
        <input type ="button" id="updatebtn" value="Update values" onclick="addItemsToColumns()" />