惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Threatpost
NISL@THU
NISL@THU
L
LINUX DO - 最新话题
T
The Exploit Database - CXSecurity.com
Schneier on Security
Schneier on Security
I
Intezer
T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
S
Secure Thoughts
U
Unit 42
aimingoo的专栏
aimingoo的专栏
L
LangChain Blog
B
Blog RSS Feed
Forbes - Security
Forbes - Security
D
DataBreaches.Net
D
Docker
M
MIT News - Artificial intelligence
F
Full Disclosure
N
News and Events Feed by Topic
T
Tor Project blog
MyScale Blog
MyScale Blog
博客园 - 叶小钗
SecWiki News
SecWiki News
IT之家
IT之家
云风的 BLOG
云风的 BLOG
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Security Blog
Microsoft Security Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
The Register - Security
The Register - Security
T
Threat Research - Cisco Blogs
博客园 - 聂微东
T
Troy Hunt's Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Latest
Security Latest
N
News and Events Feed by Topic
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
P
Proofpoint News Feed
S
Securelist
PCI Perspectives
PCI Perspectives
美团技术团队
V
V2EX
P
Privacy & Cybersecurity Law Blog

博客园 - Windie Chai

为SharePoint顶部链接开发自定义数据源 SharePoint 2010 JavaScript技巧两则 Windows Phone Background Agent杂谈 Linq to SharePoint,看上去很美 Windows Phone自定义主题 Windows Phone WebBrowser的技巧 《Visual Studio程序员箴言》笔记 HTML5学习碎片 Windows Phone 7 UI设计和交互规范随笔(2) Windows Phone 7 UI设计和交互规范随笔(1) 使用SharePoint Client OM来查询列表的注意事项 小心Windows Live Writer插件偷走你的博客密码 [C#]增强响应性,用加载窗体(Splash)来载入主窗体 WindStyle ExifInfo for Windows Live Writer发布 WF4.0活动模型(1):工作流既活动 泛谈SharePoint 2010无代码工作流 如何在SharePoint 2010项目中引用UserProfiles.dll Windstyle SlugHelper for Windows Live Writer发布 让代码看起来更舒服(2):选择适合的字体
使用SharePoint Client OM来查询列表的注意事项(2)
Windie Chai · 2010-11-05 · via 博客园 - Windie Chai

2010-11-05 15:16  Windie Chai  阅读(1106)  评论()    收藏  举报

上一篇文章提到了使用Client OM来查询SharePoint列表时需要两次指定结果集里包含的字段,范例是C#调用托管的Client OM,本文来介绍一下如何JavaScript来调用Client OM查询列表。

先创建几个全局变量:

var tf_contex;
var tf_list;
var tf_items;

function DoQuery() {
    tf_context = new SP.ClientContext.get_current();
    tf_list = tf_context.get_web().get_lists().getByTitle("TestList");
 
    var query = new SP.CamlQuery();
    query.set_viewXml("<View><ViewFields><FieldRef Name='Entity_SysCode'/></ViewFields><Query><Where><Contains><FieldRef Name='_x822a__x73ed_'/><Value Type='Text'>"
        + "CA1143"
        + "</Value></Contains></Where></Query></View>");
 
    tf_items = tf_list.getItems(query);
 
    tf_context.load(tf_items,"Include(Entity_SysCode,_x8f66__x8f86__x724c__x7167_,_x822a__x73ed_)");
 
    tf_context.executeQueryAsync(onListsLoaded, onQueryFailed);
}

可以发现使用JavaScript来调用Client OM和使用托管代码很像,我们依然要两次指定结果集里要包含的字段,第一次是在CamlQuery.set_viewXml方法中,第二次是在clientContext.load方法中。

最后在调用context.executeQueryAsync方法时,传递了两个方法引用,第一个会在executeQueryAsync执行成功时触发,第二个则是在发生错误时触发,这两个方法的代码如下:

function onListsLoaded() {
    var items = tf_items.getEnumerator();
    while (items.moveNext()) {
        alert(item.get_item("Entity_SysCode"));
    }
}
 
function onQueryFailed(sender, args) {
    alert('Request failed. \nError: ' + args.get_message() +'\nStackTrace: ' + args.get_stackTrace());
}

当然,仅仅这样还是不够的,还得让页面执行上面的初始化函数,因为JavaScript Client OM定义在SP.js这个文件中,所以我们还得确保这个文件已经被加载完毕,Client OM专门提供了一个方法来做这件事情:

SP.SOD.executeOrDelayUntilScriptLoaded(DoQuery, "SP.js");

SharePoint 2010提供的Client OM是一套强大而又便利的API,使用Client OM,以前我们在SharePoint上进行的许多展示型开发,现在只需要一个存放代码的文档库,再搭配SharePoint内置的“内容编辑器”Web部件”就可以做到,再也不需要服务器的管理权限了。