Sharepoint学习笔记—ECMAScript对象模型系列-- 7、获取和修改List的Lookup字段
在前面我们提到了如何使用ECMAscript对象模型来操作普通的List Items,但如果我们操作的List包含有Lookup字段,那么我们又该怎么做呢?
首先参考此文搭建我们本文的测试环境
Sharepoint学习笔记---SPList--创建一个带有Lookup字段的List
一、对于获取操作,我们使用如下代码
function GetLookupValue() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('TestSale');
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, 'Include(ProductName,LookupStaffName)');
context.executeQueryAsync(Function.createDelegate(this, this.successGetLookupValue),
Function.createDelegate(this, this.failedGetLookupValue));
}
function successGetLookupValue() {
var TextFiled = "";
var ListEnumerator = this.allItems.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
TextFiled += currentItem.get_item('ProductName') + '-' + currentItem.get_item('LookupStaffName').get_lookupValue() + '\n';
}
alert(TextFiled);
}
function failedGetLookupValue(sender, args) {
alert("failed. Message:" + args.get_message());
}
</script>
效果如下:
二、对于修改操作,我们使用如下代码
function SetLookupValue() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('TestSale');
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, 'Include(ProductName,LookupStaffName)');
context.executeQueryAsync(Function.createDelegate(this, this.successSetLookupValue), Function.createDelegate(this, this.failedSetLookupValue));
}
function successSetLookupValue() {
var TextFiled = ""
var ListEnumerator = this.allItems.getEnumerator();
while (ListEnumerator.moveNext()) {
var currentItem = ListEnumerator.get_current();
var newLookupField = new SP.FieldLookupValue();
newLookupField.set_lookupId(2) //Updated with some lookup value for LookupStaffName column
// Here is an id of your lookup list item 'Steve';
currentItem.set_item('LookupStaffName', newLookupField);
currentItem.update();
// Call context.executeQueryAsync again
}
}
function failedSetLookupValue(sender, args) {
alert("failed. Message:" + args.get_message());
}
</script>
效果如下:
需要说明的是,在修改中,我们使用到代码
此代码中参数的含意就是从LookupItem所绑定的数据源List中去取值,如下图:
转载于:https://www.cnblogs.com/wsdj-ITtech/archive/2012/06/06/2418912.html
Sharepoint学习笔记—ECMAScript对象模型系列-- 7、获取和修改List的Lookup字段相关推荐
- Sharepoint学习笔记—ECMAScript对象模型系列-- 8、组与用户操作(一)
这里总结一下关于使用ECMAscript对象模型来操作Goup与User的常用情况,因为内容较多,所以拆分为两个部分,这部分主要内容如下: 1.取得当前Sharepoint网站所有的Grou ...
- Sharepoint学习笔记—ECMAScript对象模型系列-- 9、组与用户操作(二)
接着上面的继续,这里我们描述的关于User与Group的操作如下: 6. 向指定Group中添加指定User 7. 获取指定Group的Owner 8. 把当前登录用户添加到指定G ...
- Sharepoint学习笔记—Site Definition系列-- 2、创建Content Type
Sharepoint本身就是一个丰富的大容器,里面存储的所有信息我们可以称其为"内容(Content)",为了便于管理这些Conent,按照人类的正常逻辑就必然想到的是对此进行&q ...
- SharePoint【ECMAScript对象模型系列】-- 07. 获取和修改List的Lookup字段
在前面我们提到了如何使用ECMAscript对象模型来操作普通的List Items,但如果我们操作的List包含有Lookup字段,那么我们又该怎么做呢? 首先参考此文搭建我们本文的测试环境 Sha ...
- Sharepoint学习笔记—Site Definition系列-- 3、创建ListDefinition
创建一个List Definition有多条途径,这里由于我们要基于前面的用户自定义Content Type来创建一个List Defintion,所以我们就需要使用到List Definition ...
- Sharepoint学习笔记—Site Definition系列-- 1、创建Site Columns
https://www.cnblogs.com/wsdj-ITtech/archive/2012/08/12/2470219.html Site Columns是Sharepoint网站的一个重要底层 ...
- Sharepoint学习笔记—Site Definition系列-- 5、List Definition与List Template之比较
在上一篇我们试图通过List Template来帮助我们相对较快的创建我们List Definition中的Schema.xml文件,你可能会发现,我们并不能照搬List Template中相应的定义 ...
- sharepoint ECMAScript对象模型系列
转载:Sharepoint学习笔记-ECMAScript对象模型系列-- 8.组与用户操作(一) http://www.cnblogs.com/wsdj-ITtech/archive/2012/06/ ...
- Sharepoint学习笔记—架构系列
为便于查阅,这里整理并列出了我的Sharepoint学习笔记中涉及架构方面的有关文章,有些内容可能会在以后更新. Sharepoin学习笔记-架构系列-- Sharepoint的网页(Page), ...
最新文章
- python基础---元组、字典、函数、文件、异常
- easyui-treegrid移除树节点出错
- pjsip学习笔记二
- Spring 定时器
- 学python就业要看哪些书-人人学Python,为什么就业拿高薪的那么少?
- setDrawingCacheEnabled(boolean flag)
- SpringMvc Intercetor
- CPU占用率是什么?
- 李开复发布新书《AI未来》,答技术大变革下的生存法则,LeCun纳德拉推荐
- Delphi 与 DirectX 之 DelphiX(23): TDirectDrawSurface.Blur;
- HDU 3709 Balanced Number 枚举+数位DP
- 《Java多线程编程核心技术》学习笔记(1)
- mysql insert on duplicate_一条Insert on duplicate引发的血案
- 揭秘 typedef四用途与两陷阱
- python海龟绘图小猪佩奇_海龟绘图(Turtle Graphics)
- 《Android群英传》读书笔记
- 计算机启动突然断电,电脑启动运行过程主机突然断电怎么办
- Hadoop是什么?(处理大数据存储和分析的基础架构)
- Android-记账本(一)-效果图
- jango model.obejcts.filter 查询指定字段
热门文章
- 调用方法[manageapp]时发生异常_探讨通过Feign配合Hystrix进行调用时异常的处理
- web---基础知识(更新中)
- 伪元素写竖线_用伪元素画出太极图
- python编程高手教程_写给编程高手的Python教程(11) 深入类和对象
- @override注解可以不写吗
- python 去掉文件头部几行_批量重命名文件的python代码
- 语言 山东专升本 真题_专升本英语真题
- nacos enablediscoveryclient_Nacos入门指南03 服务发现实践
- chart.js 饼图显示百分比_Echarts饼图展示车站客流占比图
- 出现“Could not resolve host: www.github.com; Unknown error”错误解决