Created
February 5, 2012 09:45
-
-
Save emiliano-poggi/1744459 to your computer and use it in GitHub Desktop.
Javascript to display sharepoint list items on page load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server"> | |
<script type="text/javascript"> | |
window.onload = function() { | |
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js"); | |
} | |
</script> | |
<div id="test"> | |
</div> | |
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<asp:Content ContentPlaceHolderId="PlaceHolderAdditionalPageHead" runat="server"> | |
<SharePointWebControls:ScriptLink Name="SP.js" runat="server" OnDemand="true" Localizable="False" /> | |
<script src="/cs/Style Library/CustomStyles/scripts/jquery.tools.min.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
function ViewItem() | |
{ | |
var context = new SP.ClientContext.get_current(); | |
var web = context.get_web(); | |
var list = web.get_lists().getByTitle('Service Basket'); | |
var query = SP.CamlQuery.createAllItemsQuery(); | |
allItems = list.getItems(query); | |
context.load(allItems, 'Include(Title)'); | |
context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed)); | |
} | |
function success() { | |
var TextFiled = ""; | |
var ListEnumerator = this.allItems.getEnumerator(); | |
$('#test').append('<ul>'); | |
while(ListEnumerator.moveNext()) | |
{ | |
var currentItem = ListEnumerator.get_current(); | |
$('#test').append('<li>'+currentItem.get_item('Title') + '</li>\n'); | |
} | |
$('#test').append('</ul>'); | |
} | |
function failed(sender, args) { | |
alert("failed. Message:" + args.get_message()); | |
} | |
</script> | |
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server"> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js"); | |
}) | |
</script> | |
<div id="test"> | |
</div> | |
</asp:Content> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server"> | |
<script type="text/javascript"> | |
$(function(){ | |
ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js"); | |
}) | |
</script> | |
<div id="test"> | |
</div> | |
</asp:Content> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment