When developing applications using the ecmascript object model, we do not consciously want to know what methods a certain SP object provides? Here we will look at how to do it.
1. Add a visual webpart (named wplkecmascript) and a Javascript file (named ecmaoplistitems. JS) to the SharePoint project we created earlier)
The code for ecmaoplistitems. JS is as follows. This code is used in the previous introduction to extract website attributes.
// Retrive website Properties
VaR siteurl = '/';
Function retrivewebsiteproperties (){
VaR clientcontext = new sp. clientcontext (siteurl );
// Var clientcontext = new sp. clientcontext. get_current ();
This. owebsite = clientcontext. get_web ();
Clientcontext. Load (this. owebsite, 'title', 'created '); // load the specific properties of website object
Clientcontext.exe cutequeryasync (function. createdelegate (this, this. onquerysucceededproperties ),
Function. createdelegate (this, this. onqueryfailedproperties ));
}
Function onquerysucceededproperties (sender, argS ){
Alert ('title: '+ this. owebsite. get_title () + 'created:' + this. owebsite. get_created ());
// Alert ('title ');
}
Function onqueryfailedproperties (sender, argS ){
Alert ('request failed. '+ args. get_message () +' \ n' + args. get_stacktrace ());
// Alert ('failed ');
}
Register the ecmaoplistitems. js we added above in wplkecmascript's wplkecmascript. cs. The Code is as follows:
Using system;
Using system. componentmodel;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using Microsoft. SharePoint;
Using Microsoft. Sharepoint. webcontrols;
Namespace jsomtest. wplkecmascript
{
[Toolboxitemattribute (false)]
Public class wplkecmascript: webpart
{
// Visual Studio might automatically update this path when you change the Visual Web Part project item.
Private const string _ ascxpath = @"~ /_ Controltemplates/jsomtest/wplkecmascript/wplkecmascriptusercontrol. ascx ";
Protected override void createchildcontrols ()
{
Control control = page. loadcontrol (_ ascxpath );
Controls. Add (control );
Scriptlink. Register (this. Page, "/_ layouts/jsomtest/ecmaoplistitems. js", true );
}
}
}
The wplkecmascript interface adds a button to activate the above function. The Code is as follows:
<Br/>
<Input id = "btnretrievewebsiteproperties" type = "button" value = "retrievewebsiteproperties"
Onclick = 'retrivewebsiteproperties () '/>
Project:
2. Add the developed visual webpart to the SharePoint website and run the SharePoint application. When the application interface is displayed, as shown in
3. Call the Developer Tools tool of IE as follows:
4. Select the script page of developer tools.
5. Select the Javascript file you want to debug. Here we want to debug ecmaoplistitems. JS, so select it.
6. Set the breakpoint in the commit Crip code, select start debugging on Developer Tools, and run the function buttons on our webpage.
7. Select the objects we are interested in at the breakpoint and view their methods.
Reprinted: http://www.cnblogs.com/wsdj-ITtech/archive/2012/05/08/2415303.html