Look at the final effect. The following picture is the preliminary planned function, which mainly designs the creation, query and management of lists. It also involves the case of uploading files. If there are any important ones, they will be gradually added in the future.
The link inside will call the UI Javascript interface to create a SharePoint2010 style pop-up window. The background page of the pop-up window is located in the SitePage document library. Please note that this only applies to the opened page if it is a WebPart page. If it is not opened, it will Error reported: "The Ribbon Tab with id: "Ribbon.Read" has not been made available for this page or does not exist".
(Note that this Page will not be used in the future, it is left here only to explain the use of Ribbon)
Create a list:
First, through Designer, add the following two Script links:
ECMAScriptOM and .NET Managed ClientOM (which will be discussed later) have the same purpose, but there are a few points to note:
Server-side URLs cannot be used in ClientContext;
LINQ is not supported;
Essentially ECMAScript OM is asynchronous
The code is very simple and easy to understand. There is a fun thing in it, SP.UI.Notify.addNotification. Through this class, prompt messages can be displayed in the calling screen, very SharePoint.
The demonstration results are as follows:
After entering the list name in the text box, click the "Create List" button. After the list is generated, "List test1 created" will be prompted in the upper right corner. In this example, annoucement is used as the list type.
Similarly, take a look at the effect first. Click the "Get All List" button to read all the lists under the current site and set the corresponding hyperlink attributes. Click the "Hide List" button to hide them ( It’s actually a Div)
The code is very straightforward and only explains one point. The use of JavaScript functions such as getEnumerator() and moveNexst(), get_current() provides a good way to traverse the collection.
function getLists(){ var clientContext = new SP.ClientContext(); var oWebSite = clientContext.get_web(); listCollection = oWebSite.get_lists(); clientContext.load(listCollection); clientContext. executeQueryAsync(Function.createDelegate(this, this.onGetListsSucceeded), Function.createDelegate(this, this.onGetListsFailed)); } function onGetListsSucceeded(){ var str = ""; var listsEnumerator = listCollection.getEnumerator(); while(listsEnumerator.moveNext()){ var objList = listsEnumerator.get_current(); str = "" objList.get_title() "" " "; } document.getElementById(" lists").innerHTML = str; } function onGetListsFailed(sender, args){ alert('Request failed. ' args.get_message() 'n' args.get_stackTrace()); }
CAML query:
There are two ways to query, one by DueDate and one by Title. Of course, the function can be designed to be more user-friendly, and there will be no excessive rendering in the Demo. Click Search to query the data. I made a small discovery. If you select a date when using the control, it will cause the page to postback. There are at least two solutions in SharePoint:
Put the calendar control in a separate page, and then add the following code:
Use the SharePoint Calendar control
I did a section to control the display of controls. Select Date and a control for inputting Date will appear. Select Title and a control for inputting Title will appear. I originally wanted to use the JQuery method, but then I suddenly didn’t remember how to write JQuery’s Selector. I was confused. The foreign ones use the following method to combine control:
The details of CAML query itself are not explained too much. If you are interested, you can refer to my article (http://www.cnblogs.com/johnsonwong/archive/2011/02/27/1966008.html). This is This article is for the 2007 version of CAML. There have been many enhancements in 2010, such as cross-list Joint query, etc. The corresponding 2010 version will be released later.
The knowledge that needs to be paid attention to is:
uses field query, pay attention to the relevant API calls; ClientContext operates on several result sets, but needs to call Load to Load different result sets: clientContext.load(fieldCollection); clientContext.load(listItemCollection); If there are field values that need to be read, a description needs to be displayed in the CAML query XML, otherwise it will not be returned to the result set. This Also for performance reasons
function search(){ var clientContext = new SP.ClientContext(); var oWebSite = clientContext.get_web(); var list = oWebSite.get_lists().getByTitle("Tasks"); fieldCollection = list .get_fields(); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml( "" "" "2008-01-1T00:00:00Z" "" "" "" ""); listItemCollection = list.getItems(camlQuery); clientContext.load(fieldCollection); clientContext.load( listItemCollection); clientContext.executeQueryAsync(Function.createDelegate(this, this.onSearchListSucceeded), Function.createDelegate(this, this.onSearchListFailed)); } function onSearchListSucceeded(){ var str = ""; var listItemEnumerator = listItemCollection.getEnumerator(); var fieldsEnumerator = fieldCollection.getEnumerator(); while(listItemEnumerator.moveNext()){ var oListItem = listItemEnumerator.get_current( ); str = "Item " oListItem.get_id() ":" while(fieldsEnumerator.moveNext()){ var oField = fieldsEnumerator.get_current(); str = oField.get_staticName () " "; } str = " "; } document.getElementById("lists").innerHTML = str; }
function onSearchListFailed(sender, args){ alert('Request failed. ' args.get_message() 'n' args.get_stackTrace()); }
Operating files:
Unfortunately, files cannot be uploaded in ECMAScript. Although there is an SP.File object, most of the operations are on the obtained SP.File object.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn