承接MOSS各种工作流开发 联系人:王先生.电话:18618405729QQ:252385878 QQ群:41696750 MSN:wanghao-3@hotmail.com

导航

ECMAScript Client OM(传说中的js客户端编程)

把这个aspx文件放在_layouts下面,直接通过js访问后台文件

 

 

<%@ Page Language="C#" %>
<%@ Register Tagprefix="SharePoint"
    Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>ECMAScript Client OM</title>
      <script type="text/javascript">


          function CallClientOM() {
              var context = new SP.ClientContext.get_current();
              this.website = context.get_web();
       this.listCollection = website.get_lists();

              context.load(this.listCollection, 'Include(Title, Id)');
              context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
          }


          function onQuerySucceeded(sender, args) {

   var listInfo = '';

   var listEnumerator = listCollection.getEnumerator();

          while (listEnumerator.moveNext())
          {
              var list = listEnumerator.get_current();
              listInfo += 'List Title: ' + list.get_title() + ' ID: ' + list.get_id() + '\n';
          }
    alert(listInfo);

          }

          function onQueryFailed(sender, args) {
              alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
          }

      </script>       
  </head>
  <body>
    <form id="form1" runat="server">
      <SharePoint:ScriptLink ID="ScriptLink1" Name="sp.debug.js" LoadAfterUI="true" Localizable="false" runat="server" />
 
<a href="#" onclick="CallClientOM()">Click here to Execute</a>

      <SharePoint:FormDigest runat="server" />
    </form>
  </body>
</html>

 

posted on 2011-01-05 22:57  A A  阅读(509)  评论(0编辑  收藏  举报