admin管理员组文章数量:1291251
I have a list where I am storing the image URLs and I am trying to read list of items and display the images on the page. For that I wrote the script something like below....
<script type="text/javascript">
function ViewItem()
{
var myQueryString = '<Query><Where><Eq><FieldRef Name="Anchor" /><Value
Type="Boolean">1</Value></Eq></Where></Query>';
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('AnchorImageList');
var myquery = new SP.CamlQuery();
myquery.set_viewXml(myQueryString);
myItems = list.getItems(myquery);
context.load(myItems, 'Include(Title,ImageURL)');
context.executeQueryAsync(Function.createDelegate(this, this.success),
Function.createDelegate(this, this.failed));
}
function success()
{
var LinkURL= "";
var ImageURL="";
var ListEnumerator = this.myItems.getEnumerator();
while(ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
LinkURL = currentItem.get_item('Title') ;
ImageURL= currentItem.get_item('ImageURL');
document.write('<img src="' + ImageURL+ '"+>');
alert(LinkURL);
}
}
function failed(sender, args)
{
alert("failed. Message:" + args.get_message());
}
</script>
<a href="#" onclick="Javascript:ViewItem();">View Items</a>
In my CAML query I am trying to filter items which are tagged yes for "Anchor?"(yes/no column).
But I am seeing all the results even though I tagged few items not to display. What I am doing wrong here. Please someone help me. Also,after the images are loaded on the page, the page is still showing the wheel as if it is processing something. Do I need to do something for this?
I have a list where I am storing the image URLs and I am trying to read list of items and display the images on the page. For that I wrote the script something like below....
<script type="text/javascript">
function ViewItem()
{
var myQueryString = '<Query><Where><Eq><FieldRef Name="Anchor" /><Value
Type="Boolean">1</Value></Eq></Where></Query>';
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('AnchorImageList');
var myquery = new SP.CamlQuery();
myquery.set_viewXml(myQueryString);
myItems = list.getItems(myquery);
context.load(myItems, 'Include(Title,ImageURL)');
context.executeQueryAsync(Function.createDelegate(this, this.success),
Function.createDelegate(this, this.failed));
}
function success()
{
var LinkURL= "";
var ImageURL="";
var ListEnumerator = this.myItems.getEnumerator();
while(ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
LinkURL = currentItem.get_item('Title') ;
ImageURL= currentItem.get_item('ImageURL');
document.write('<img src="' + ImageURL+ '"+>');
alert(LinkURL);
}
}
function failed(sender, args)
{
alert("failed. Message:" + args.get_message());
}
</script>
<a href="#" onclick="Javascript:ViewItem();">View Items</a>
In my CAML query I am trying to filter items which are tagged yes for "Anchor?"(yes/no column).
But I am seeing all the results even though I tagged few items not to display. What I am doing wrong here. Please someone help me. Also,after the images are loaded on the page, the page is still showing the wheel as if it is processing something. Do I need to do something for this?
Share Improve this question edited Oct 2, 2012 at 18:29 Alexei Levenkov 101k15 gold badges135 silver badges188 bronze badges asked Oct 2, 2012 at 18:27 user346514user346514 5234 gold badges12 silver badges34 bronze badges 3- 1 +1 good question/reasonable sample. Side note on question quality: there is no need to add thank you notes (upvote/accept/ment instead) and signature as it rarely adds value to the post. – Alexei Levenkov Commented Oct 2, 2012 at 18:31
- 1 check your caml query using U2U Caml Builder – Raheel Commented Oct 3, 2012 at 2:11
- 1 I wrote the query using the u2u builder only and the query returns proper results when i execute it there. I am not sure why the same query is not working from Client object Model. – user346514 Commented Oct 3, 2012 at 13:52
3 Answers
Reset to default 3try this one:
<View>
<Query>
<Where>
<Eq>
<FieldRef Name="Anchor" />
<Value Type="Boolean">1</Value>
</Eq>
</Where>
</Query>
</View>
in case if it doesn't work for you, follow next steps:
- Create a list view using standard functionality.
- Open it at SharePoint Designier and just copy CAML query from the code.
Hope this will help.
Remove the Query
tags from the CAML query stored in myQueryString
. The tags are added implicitly when the query is run.
It's tripped me up before, too. The insidious thing about it is that the query won't ever fail outright; sometimes it works, sometimes it doesn't, making it a pain to debug.
I found that if you use just single quotes in your CAML query it will work. Mixing double and single quotes jacks up the query for some reason. Hope that helps.
本文标签: javascriptReading the list items Sharepoint 2010 client object modelStack Overflow
版权声明:本文标题:javascript - Reading the list items Sharepoint 2010 client object model - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741530633a2383735.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论