一、查询指定的Termset及子项

  1. <script type="text/javascript" src="/Style%20Library/aaaa/Scripts/jquery-1.11.1.min.js" language="javascript"></script>
  2. <script type="text/javascript">RegisterSod("sp.taxonomy.js", "\u002f_layouts\u002f15\u002fsp.taxonomy.js?rev=l0dFB37050OQxbmrgu6z7Q\u00253D\u00253D");</script>
  3.  
  4. <script type="text/javascript">
  5. $(document).ready(function () {
  6. var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
  7. $.getScript(scriptbase + "SP.Runtime.js",
  8. function () {
  9. $.getScript(scriptbase + "SP.js", function () {
  10. $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
  11. });
  12. }
  13. );
  14. });
  15. function execOperation() {
  16. //Current Context
  17. var context = SP.ClientContext.get_current();
  18. //Current Taxonomy Session
  19. var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
  20. //Term Stores
  21. var termStores = taxSession.get_termStores();
  22. //Name of the Term Store from which to get the Terms.
  23. var termStore = termStores.getByName("IdeaTracker_MMS");
  24. //GUID of Term Set from which to get the Terms.
  25. var termSet = termStore.getTermSet("bcf031d3-7eb2-433a-b5ff-b92398758431");
  26. var terms = termSet.getAllTerms();
  27. context.load(terms);
  28. context.executeQueryAsync(function () {
  29. var termEnumerator = terms.getEnumerator();
  30. var termList = "Terms: \n";
  31. while (termEnumerator.moveNext()) {
  32. var currentTerm = termEnumerator.get_current();
  33. termList += currentTerm.get_name() + "\n";
  34. }
  35. alert(termList);
  36. }, function (sender, args) {
  37. console.log(args.get_message());
  38. });
  39. }
  40. </script>

二、创建Term Group

  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
  4. $.getScript(scriptbase + "SP.Runtime.js",
  5. function () {
  6. $.getScript(scriptbase + "SP.js", function () {
  7. $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
  8. });
  9. }
  10. );
  11. });
  12.  
  13. function execOperation() {
  14. //Current Context
  15. var context = SP.ClientContext.get_current();
  16. //Current Taxonomy Session
  17. var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
  18. //Term Stores
  19. var termStores = taxSession.get_termStores();
  20. //Term Store under which to create the group.
  21. var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
  22. //New Group with name and new GUID
  23. var newGroup = termStore.createGroup("New Group Name", "b300304a-1693-4629-a1c0-dff7bda644ff");
  24. context.load(newGroup);
  25. context.executeQueryAsync(function () {
  26. console.log(newGroup.get_name());
  27. }, function (sender, args) {
  28. console.log(args.get_message());
  29. });
  30. }
  31. </script>

三、创建Term Set

  1. <script type="text/javascript">
  2. $(document).ready(function () {
  3. var scriptbase = _spPageContextInfo.webServerRelativeUrl + "_layouts/15/";
  4. $.getScript(scriptbase + "SP.Runtime.js",
  5. function () {
  6. $.getScript(scriptbase + "SP.js", function () {
  7. $.getScript(scriptbase + "SP.Taxonomy.js", execOperation);
  8. });
  9. }
  10. );
  11. });
  12.  
  13. function execOperation() {
  14. //Current Context
  15. var context = SP.ClientContext.get_current();
  16. //Current Taxonomy Session
  17. var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
  18. //Term Stores
  19. var termStores = taxSession.get_termStores();
  20. //Term Store under which to create the Term Set.
  21. var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
  22. //Get group by GUID
  23. var peopleGroup = termStore.getGroup("97eaa7b8-9778-4f61-acb3-7f47abba13c3");
  24. //Create New Term Set in Group with Name, New GUID and LCID
  25. var newTermSet = peopleGroup.createTermSet("New TermSet Name", "49dac247-d315-4065-8718-e8c3f50e7dcd", 1033);
  26. context.load(newTermSet);
  27. context.executeQueryAsync(function () {
  28. console.log(newTermSet.get_name());
  29. }, function (sender, args) {
  30. console.log(args.get_message());
  31. });
  32. }
  33. </script>

四、创建Term

  1. <script type="text/javascript">
  2. function execOperation() {
  3. //Current Context
  4. var context = SP.ClientContext.get_current();
  5. //Current Taxonomy Session
  6. var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
  7. //Term Stores
  8. var termStores = taxSession.get_termStores();
  9. //Term Store under which to create the term.
  10. var termStore = termStores.getByName("Taxonomy_Dmxzz8tIBzk8wNVKQpJ+xA==");
  11. //Term Set under which to create the term.
  12. var termSet = termStore.getTermSet("b49f64b3-4722-4336-9a5c-56c326b344d4");
  13. //Name of the term, LCID and a new GUID for the term.
  14. var newTerm = termSet.createTerm("India", 1033, "b49f64b3-4722-4336-9a5c-56c326b344a9");
  15. //newTerm.set_isAvailableForTagging(true);
  16. context.load(newTerm);
  17. context.executeQueryAsync(function () {
  18. alert("Term Created: " + newTerm.get_name());
  19. }, function (sender, args) {
  20. console.log(args.get_message());
  21. });
  22. }
  23. </script>

五、获取单一值的字段

  1. <script type="text/javascript">
  2. function execOperation() {
  3. var context = SP.ClientContext.get_current();
  4. var list = context.get_web().get_lists().getByTitle('TaxonomyCustomList');
  5. var listItem = list.getItemById(1);
  6. context.load(listItem);
  7. context.executeQueryAsync(function () {
  8. //Single Value Taxonomy Column
  9. var label = listItem.get_item("MyTaxColumn").get_label();
  10. //Term GUID
  11. var termGUID = listItem.get_item("MyTaxColumn").get_termGuid();
  12. //Type ID
  13. var typeID = listItem.get_item("MyTaxColumn").get_typeId();
  14. //WSS ID
  15. var wssID = listItem.get_item("MyTaxColumn").get_wssId();
  16. }, function (sender, args) {
  17. console.log(args.get_message());
  18. });
  19. }
  20. </script>

六、获取多选值的字段

  1. <script type="text/javascript">
  2. function execOperation() {
  3. var context = SP.ClientContext.get_current();
  4. var list = context.get_web().get_lists().getByTitle('TaxonomyCustomList');
  5. var listItem = list.getItemById(1);
  6. context.load(listItem);
  7. context.executeQueryAsync(function () {
  8. //Multivalue Taxonomy Column
  9. var taxEnumerator = listItem.get_item("MyTaxColumn").getEnumerator();
  10. while (taxEnumerator.moveNext()) {
  11. //Label
  12. var currentTerm = taxEnumerator.get_current();
  13. //Label
  14. var label = currentTerm.get_label();
  15. //Term GUID
  16. var termGUID = currentTerm.get_termGuid();
  17. //Type ID
  18. var typeID = currentTerm.get_typeId();
  19. //WSS ID
  20. var wssID = currentTerm.get_wssId();
  21. }
  22. }, function (sender, args) {
  23. console.log(args.get_message());
  24. });
  25. }
  26. </script>

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

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

    CSOM和ServerAPI 的对比 SharePoint从2010开始引入了Client Object Model的API(后文中用CSOM来代替),从名字来看,我们可以简单的看出,该API是面向客 ...

  2. 解决在使用client object model的时候报“object does not belong to a list”错误

    在查看别人代码的时候,发现了个有意思的问题,使用client object model将一个文件check in 我使用的是如下语句获取file Microsoft.SharePoint.Client ...

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

    很多人在用client object model的时候,不知道何时或者该不该load,今天看到一个观点描述这个问题,觉得很有道理,和大家分享.那就是写client object model就像写sql ...

  4. SharePoint 2010 匿名用户调用Client Object Model访问列表项

    最近有个小需求,在门户首页上加个通知公告的版块,新闻来源是列表项,需要有垂直滚动的效果. 第一个想法就是通过SharePoint的Client Object Model获取列表数据再加上JQuery来 ...

  5. c# sharepoint client object model 客户端如何创建中英文站点

    c# sharepoint client object model 客户端如何创建中英文站点 ClientContext ClientValidate = tools.GetContext(Onlin ...

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

    自从人类学会了使用火,烤制的方式替代了人类的消化系统部分功能,从此人类的消化系统更加简单,加速了人脑的进化:自从SharePoint 2010开始有了Client Side Object Model ...

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

    1. 新建一个C#的Console project. 2. 给project 添加reference: Microsoft.SharePoint.Client Microsoft.SharePoint ...

  8. [SharePoint]javascript client object model 获取lookup 类型的field的值,包括user类型(单人或者多人)的值。how to get the multiple user type/lookup type field value by Javascript client object model

    1. how to get value var context = new SP.ClientContext.get_current(); var web = context.get_web(); v ...

  9. DHTML Object Model&DHTML&DOM

    DHTML Object Model:DHTML对象模型,利用DHTML Object Model可以单独操作页面上的对象,每个HTML标记通过它的ID和NAME属性被操纵,每个对象都具有自己的属性. ...

随机推荐

  1. OC和C++的区别

    C++语言特点: 1.在C语言的基础上进行扩充和完善,使C++兼容了C语言的面向过程特点,又成为了一种面向对象的程序设计语言: 2.可以使用抽象数据类型进行基于对象的编程: 3.可以使用多继承.多态进 ...

  2. C++ string头文件

    转载自https://blog.csdn.net/superna666/article/details/52809007/ 作者 zhenzhenjiajia888 标准c++中string类函数介绍 ...

  3. c++ 指针数组,输入4个季度的花费,计算出总花费

    #include <iostream> #include <array> #include <string> const int Seasons = 4; cons ...

  4. Linux基础学习-LVM逻辑卷管理遇到的问题

    LVM学习逻辑卷管理创建逻辑卷遇到的问题 1 实验环境 系统 内核 发行版本 CentOS 2.6.32-754.2.1.el6.x86_64 CentOS release 6.10 (Final) ...

  5. 拓展jQuery的serialize(),将form表单转化为json对象

    jQuery 的 serialize() 方法经常会报 Uncaught TypeError: JSON.serializeObject is not a function 的错误, 原装的方法真的一 ...

  6. vue_music:封装scroll.vue组件

    在项目中经常用到滚动,结合Better-scroll封装了sroll.vue组件参考链接:https://ustbhuangyi.github.io...http://www.imooc.com/ar ...

  7. Vue表单输入绑定

    <h3>基础用法</h3> <p>你可以用<strong>v-model</strong>指令在表单input,textarea以及sele ...

  8. 剑指Offer(书):顺时针打印数组

    题目:输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1 ...

  9. 《鸟哥的Linux私房菜》学习笔记(1)——文件与目录

    在Linux中,任何设备都是文件,不仅如此,连数据通信的接口也有专门的文件负责.可以说,一切皆文件,目录也是一种文件,是路径映射.因此,文件系统是Linux的基础. 一.文件与目录管理命令 1.ls( ...

  10. HBase0.94.2-cdh4.2.0需求评估测试报告1.0之二

    Hbase 配置文件: hbase-site.xml <configuration> <property> <name>hbase.cluster.distribu ...