关于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>
关于Metadata Client Object Model 的一些操作的更多相关文章
- SharePoint Client Object Model API 介绍以及工作原理解析
CSOM和ServerAPI 的对比 SharePoint从2010开始引入了Client Object Model的API(后文中用CSOM来代替),从名字来看,我们可以简单的看出,该API是面向客 ...
- 解决在使用client object model的时候报“object does not belong to a list”错误
在查看别人代码的时候,发现了个有意思的问题,使用client object model将一个文件check in 我使用的是如下语句获取file Microsoft.SharePoint.Client ...
- 关于SharePoint 的Client object model该何时load和execut query的一点自己的看法
很多人在用client object model的时候,不知道何时或者该不该load,今天看到一个观点描述这个问题,觉得很有道理,和大家分享.那就是写client object model就像写sql ...
- SharePoint 2010 匿名用户调用Client Object Model访问列表项
最近有个小需求,在门户首页上加个通知公告的版块,新闻来源是列表项,需要有垂直滚动的效果. 第一个想法就是通过SharePoint的Client Object Model获取列表数据再加上JQuery来 ...
- c# sharepoint client object model 客户端如何创建中英文站点
c# sharepoint client object model 客户端如何创建中英文站点 ClientContext ClientValidate = tools.GetContext(Onlin ...
- 在C#开发中如何使用Client Object Model客户端代码获得SharePoint 网站、列表的权限情况
自从人类学会了使用火,烤制的方式替代了人类的消化系统部分功能,从此人类的消化系统更加简单,加速了人脑的进化:自从SharePoint 2010开始有了Client Side Object Model ...
- 记一个使用Client Object Model上传文件的小例子
1. 新建一个C#的Console project. 2. 给project 添加reference: Microsoft.SharePoint.Client Microsoft.SharePoint ...
- [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 ...
- DHTML Object Model&DHTML&DOM
DHTML Object Model:DHTML对象模型,利用DHTML Object Model可以单独操作页面上的对象,每个HTML标记通过它的ID和NAME属性被操纵,每个对象都具有自己的属性. ...
随机推荐
- 解决升级mac os X EI Capitan后遇到LibclangError: dlopen(libclang.dylib, 6): image not found.的问题
打开文件./frameworks/cocos2d-x/tools/bindings-generator/clang/cindex.py 把第 3395 行 改为 : library = cdll.Lo ...
- jq封装插件,简单dome
(function($) { $.fn.extend({ bold: function() { this.css({ fontWeight: "bold", color: 'red ...
- 2829: 高精A+B [1*+]
题目描述 输入A和B,计算A+B的值 Input 两行数据,分别是A和B 0<=A<=1E200 0<=B<=10^200 Output A+B的结果 Sample Input ...
- 图解一致性协议2PC和3PC
原图地址:https://www.processon.com/diagraming/5b89f6ace4b0d4d65bf10786
- Python基础学习总结__Day3
一.集合 1.特性:无序且天生去重,格式为{} 2.作用: (1)去重 (2)关系测试 3.可调用函数(常见对列表操作) (1)取交集:A.intersection(B) (2)取并集:A.union ...
- Python 成长之路
Python roadmap python 基础 ... 内置常用函数.三元运算.递归 迭代器和生成器 模块和常用的模块 面向对象 对向对象进阶 网络编程 并发编程 ... 数据库 MySQL pym ...
- pandas-Notes2
#coding = utf-8 import pandas as pd import numpy as np import matplotlib as plt dates = pd.date_rang ...
- HDU 4965 Fast Matrix Calculation 矩阵快速幂
题意: 给出一个\(n \times k\)的矩阵\(A\)和一个\(k \times n\)的矩阵\(B\),其中\(4 \leq N \leq 1000, \, 2 \leq K \leq 6\) ...
- HDU 3315 KM My Brute
参考题解 二分图的最优匹配.图很容易建立.再处理相似度的时候.把每个权值扩大100倍.然后再对i==j时 特殊标记.使他们的权值再++1.后面选择的时候就很容易挑出.按原匹配 匹配的个数. 100*( ...
- 2019年北航OO第四次博客总结<完结撒花>
一.UML单元架构设计 1. 类图解析器架构设计 1.1 UML类图 这次作业的目标是要解析一个UML类图,首先为了解耦,我新建了一个类UmTree进行解析工作,而Interaction类仅仅作为实现 ...