A simple example of the SharePoint ECMAScript client model

Source: Internet
Author: User
Tags object model microsoft website

The ECMAScript client model is the three client model introduced by SHAREPOINT2010. NET managed "," ECMAScript "," sliverlight "one kind, today just saw this, tried, also took out and everybody share under. I myself feel that the client model, and the SP's object model is not too different, is to use, even less handy. Today wrote the next script, a variety of not so, all kinds of debugging, all kinds of depressed, hey. What a melancholy word. Well, no crap.

The advantage of the client object model is that client programming can be done without a server. For example, I am a small moss user, then I do not have access to the server, I can use the designer. First, create a new ASPX page, add a sp.js reference to the header, and we can write our client model code on this page. Add location at top placeholderadditionalpagehead this node, add <sharepoint:scriptlink name= "sp.js" runat= "Server" ondemand= "true "Localizable= False" ></sharepoint:ScriptLink> JS reference.

Here is an example of what I did: Write <script> on the page, and then write our JS script, and feel the syntax of the format, and the SP object model is very similar to the first is to open the Web site, open the list, and then find the list items on it. However, and the SP object model is still different, the SP object model, the object can be generated to invoke the value of the inside, and the client object model, but also need to load, you can take the value inside. When you write JS, be sure to pay attention to spelling!!! The lesson of blood, because the debugging is very inconvenient, so the first time to write, should be careful.

My example writes a Getlistitem function, and then reads the items in the list, reads the entries from the list, and then displays them as you click the button. Code attached to the back, interested friends, you can try. The effect is the figure below, after clicking, the following is the image of the blue box. Oneself is also the first to know ECMAScript, take out and share with you, if there is where to say the wrong place, you are welcome to comment. Of course, we could not remember the use of each object, we can visit the Microsoft website, to query the object we need to define the methods and variables, you can click on the following address http://msdn.microsoft.com/en-us/library/ee538253.aspx

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/web/sharepoint/

 <script type= "Text/javascript" > Function Getlistitem () {var mycontext=new SP.
  ClientContext ();
  var mysite=mycontext.get_web (); var query = new SP.
Camlquery ();
  
  Query.set_viewxml ("<View><Query></Query></View>");
  var mylist=mysite.get_lists (). Getbytitle (' myfirstlists ');
  
  myitem= mylist.getitems (query);
  Mycontext.load (myitem); Mycontext.executequeryasync (Function.createdelegate (this,this.getsuccessed), function.createdelegate (This,
 this.getfailed));
 function getsuccessed () {var str= "";
 var listse=myitem.getenumerator ();   
 while (Listse.movenext ()) {str+=listse.get_current (). get_item ("Title") + "<br>";
  
 } document.getElementById ("lists"). Innerhtml=str;
 function getfailed (Sender,args) {alert ("failed~!"); } </script> <div><input value= "Get2" type= "button" onclick= "Getlistitem ()"/></div> <div ID = "Lists" ></DIV> 

JS is very simple to write, I hope we do not laugh, if there are good suggestions or opinions, I hope you give me a message, welcome to discuss.

Author: Lin Yu

Source: Http://www.cnblogs.com/jianyus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.