关于Metadata Client Object Model 的一些操作

一、查询指定的Termset及子项

<script type="text/javascript" src="/Style%20Library/aaaa/Scripts/jquery-1.11.1.min.js" language="javascript"></script>
    <script type="text/javascript">RegisterSod("sp.taxonomy.js", "\u002f_layouts\u002f15\u002fsp.taxonomy.js?rev=l0dFB37050OQxbmrgu6z7Q\u00253D\u00253D");</script>

    <script type="text/javascript">
        $(document).ready(function () {
            var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
            $.getScript(scriptbase + "SP.Runtime.js",
                function () {
                    $.getScript(scriptbase + "SP.js", function () {
                        $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
                    });
                }
            );
        });
        function execOperation() {
            //Current Context
            var context = SP.ClientContext.get_current();
            //Current Taxonomy Session
            var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
            //Term Stores
            var termStores = taxSession.get_termStores();
            //Name of the Term Store from which to get the Terms.
            var termStore = termStores.getByName("IdeaTracker_MMS");
            //GUID of Term Set from which to get the Terms.
            var termSet = termStore.getTermSet("bcf031d3-7eb2-433a-b5ff-b92398758431");
            var terms = termSet.getAllTerms();
            context.load(terms);
            context.executeQueryAsync(function () {
                var termEnumerator = terms.getEnumerator();
                var termList = "Terms: \n";
                while (termEnumerator.moveNext()) {
                    var currentTerm = termEnumerator.get_current();
                    termList += currentTerm.get_name() + "\n";
                }
                alert(termList);
            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    </script>

二、创建Term Group

<script type="text/javascript">
        $(document).ready(function () {
            var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
            $.getScript(scriptbase + "SP.Runtime.js",
                function () {
                    $.getScript(scriptbase + "SP.js", function () {
                        $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
                    });
                }
            );
        });

        function execOperation() {
            //Current Context
            var context = SP.ClientContext.get_current();
            //Current Taxonomy Session
            var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
            //Term Stores
            var termStores = taxSession.get_termStores();
            //Term Store under which to create the group.
            var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
            //New Group with name and new GUID
            var newGroup = termStore.createGroup("New Group Name", "b300304a-1693-4629-a1c0-dff7bda644ff");
            context.load(newGroup);
            context.executeQueryAsync(function () {
                console.log(newGroup.get_name());
            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    </script>

三、创建Term Set

<script type="text/javascript">
        $(document).ready(function () {
            var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
            $.getScript(scriptbase + "SP.Runtime.js",
                function () {
                    $.getScript(scriptbase + "SP.js", function () {
                        $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
                    });
                }
            );
        });

        function execOperation() {
            //Current Context
            var context = SP.ClientContext.get_current();
            //Current Taxonomy Session
            var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
            //Term Stores
            var termStores = taxSession.get_termStores();
            //Term Store under which to create the Term Set.
            var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
            //Get group by GUID
            var peopleGroup = termStore.getGroup("97eaa7b8-9778-4f61-acb3-7f47abba13c3");
            //Create New Term Set in Group with Name, New GUID and LCID
            var newTermSet = peopleGroup.createTermSet("New TermSet Name", "49dac247-d315-4065-8718-e8c3f50e7dcd", 1033);
            context.load(newTermSet);
            context.executeQueryAsync(function () {
                console.log(newTermSet.get_name());
            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    </script>

四、创建Term

<script type="text/javascript">
        function execOperation() {
            //Current Context
            var context = SP.ClientContext.get_current();
            //Current Taxonomy Session
            var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
            //Term Stores
            var termStores = taxSession.get_termStores();
            //Term Store under which to create the term.
            var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
            //Term Set under which to create the term.
            var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");
            //Name of the term, LCID and a new GUID for the term.
            var newTerm = termSet.createTerm("India", 1033, "b49f64b3-4722-4336-9a5c-56c326b344a9");
            //newTerm.set_isAvailableForTagging(true);
            context.load(newTerm);
            context.executeQueryAsync(function () {
                alert("Term Created: " + newTerm.get_name());
            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    </script>

五、获取单一值的字段

<script type="text/javascript">
        function execOperation() {
            var context = SP.ClientContext.get_current();
            var list = context.get_web().get_lists().getByTitle(‘TaxonomyCustomList‘);
            var listItem = list.getItemById(1);
            context.load(listItem);
            context.executeQueryAsync(function () {
                //Single Value Taxonomy Column
                var label = listItem.get_item("MyTaxColumn").get_label();
                //Term GUID
                var termGUID = listItem.get_item("MyTaxColumn").get_termGuid();
                //Type ID
                var typeID = listItem.get_item("MyTaxColumn").get_typeId();
                //WSS ID
                var wssID = listItem.get_item("MyTaxColumn").get_wssId();
            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    </script>

六、获取多选值的字段

<script type="text/javascript">
        function execOperation() {
            var context = SP.ClientContext.get_current();
            var list = context.get_web().get_lists().getByTitle(‘TaxonomyCustomList‘);
            var listItem = list.getItemById(1);
            context.load(listItem);
            context.executeQueryAsync(function () {
                //Multivalue Taxonomy Column
                var taxEnumerator = listItem.get_item("MyTaxColumn").getEnumerator();
                while (taxEnumerator.moveNext()) {
                    //Label
                    var currentTerm = taxEnumerator.get_current();
                    //Label
                    var label = currentTerm.get_label();
                    //Term GUID
                    var termGUID = currentTerm.get_termGuid();
                    //Type ID
                    var typeID = currentTerm.get_typeId();
                    //WSS ID
                    var wssID = currentTerm.get_wssId();
                }
            }, function (sender, args) {
                console.log(args.get_message());
            });
        }
    </script>

时间: 2024-11-03 22:26:44

关于Metadata Client Object Model 的一些操作的相关文章

SharePoint Client Object Model API 介绍以及工作原理解析

COM和ServerAPI 的对比 SharePoint从2010开始引入了Client Object Model的API(后文中用COM来代替),从名字来看,我们可以简单的看出,该API是面向客户端的应用程序的.有这个这套API,使得所有SharePoint的终端用户 可以开发自己的应用程序来访问,修改SharePoint.下面的列表简述了COM和Server API的区别:   COM Server 运行端 可以在任何能够访问SharePoint的机器上运行 可以再浏览器上,.Net应用程序

记一个使用Client Object Model上传文件的小例子

1. 新建一个C#的Console project. 2. 给project 添加reference: Microsoft.SharePoint.Client Microsoft.SharePoint.Runtime 3. 修改project的属性: Platform target – x64 Target framework – .NET Framework 4 4. 修改代码如下: using System; using System.IO; using System.Net; using

关于SharePoint 的Client object model该何时load和execut query的一点自己的看法

很多人在用client object model的时候,不知道何时或者该不该load,今天看到一个观点描述这个问题,觉得很有道理,和大家分享.那就是写client object model就像写sql语句一样.你可以随意使用写关系复杂的查询语句,当你要查看结果的时候,执行这个sql语句就行了.这里就不考虑什么代码效率的问题了,那是另一个话题. 放到client object model的意思是一样的,你可以随意使用对象以及对象的属性,构建你想要的对象,但是当你想使用这个结果对象或者想查看结果的时

在C#开发中如何使用Client Object Model客户端代码获得SharePoint 网站、列表的权限情况

自从人类学会了使用火,烤制的方式替代了人类的消化系统部分功能,从此人类的消化系统更加简单,加速了人脑的进化:自从SharePoint 2010开始有了Client Side Object Model ,我们就可以不用在服务器上开发SharePoint解决方案了,开发的方式更加多元化,这又加速了SharePoint 更大范围的应用. 现在,我们可以在任一台PC上安装Visual Studio 然后使用类似于 Object Model的模型来访问服务器上的列表.网站或是其它任何东东. 那么 ,如何使

DHTML Object Model&amp;DHTML&amp;DOM

DHTML Object Model:DHTML对象模型,利用DHTML Object Model可以单独操作页面上的对象,每个HTML标记通过它的ID和NAME属性被操纵,每个对象都具有自己的属性.方法和事件,通过方法操纵对象,通过事件触发因果过程. DOM:文档对象模型,将页面描述成一个树形的对象结构,是对DHTML Object Model的更全面的完善,可以利用树形结构对对象利用之间的关系进行操作,但是DOM不支持对事件的对象操作,这是步入DHTML Object Model不如的地方,

Client API Object Model - Form Context

FormContext 提供界面或者界面上控件的的引用. 比如说 quick view control, row in an editable grid 等等. Xrm.Page 和 getFormContext都可以用的引用. 但是Xrm.Page 将来会被弃用, 所以建议搭建开始使用getFormContext 我们来看一下Xrm.Page 和 getFormContext的区别: function displayName() { var firstName = Xrm.Page.getAt

BOM(Browser Object Model) 浏览器对象模型

JavaScript 实现是由 3 个部分组成:核心(ECMAScript),文档对象模型(DOM),浏览器对象模型(BOM) BOM(Browser Object Model) 浏览器对象模型BOM定义了JavaScript进行操作浏览器的各个功能部件的接口,提供访问文档各个功能部件(如窗口本身.屏幕功能部件.框架.浏览历史记录等)的途径以及操作方法.BOM是JavaScript应用中唯一没有相关标准的部分, ,每种浏览器都有其特有的BOM扩展实现. BOM对象 描述Window JavaSc

Document Object Model (DOM) Level 3 Events Specification

Document Object Model (DOM) Level 3 Events Specification W3C Working Draft 25 September 2014 This version: http://www.w3.org/TR/2014/WD-DOM-Level-3-Events-20140925/ Latest published version: http://www.w3.org/TR/DOM-Level-3-Events/ Latest editor's dr

Document Object Model

1. DOM => Document Object Model(文档对象模型); DOM是一个树形结构;由Node\Element(节点\元素)构成;2.Node\Element; element.id\element.className\element.value\.... element.tagName\element.nodeName => 元素的标签名; element.nodeType; => 元素的类型; Element(1); => 元素; Attbribute(2)