当前位置: 代码迷 >> SharePoint >> Ecma没法得到当前web对象
  详细解决方案

Ecma没法得到当前web对象

热度:109   发布时间:2016-05-02 07:13:11.0
Ecma无法得到当前web对象


 var ctx = new SP.ClientContext.ClientContext();//get_current();
        this.web = ctx.get_web();
        var list=this.web.get_lists().getByTitle("commendation");//对应列表名称
        var camlQuery = new SP.CamlQuery(); 
        camlQuery.set_viewXml("<View><Query><Where><Gt>" +"<FieldRef Name='Created' />" +"<Value Type='DateTime'>2008-01-1T00:00:00Z</Value>" + "</Gt></Where></Query></View>");
        listItemCollection = list.getItems(camlQuery);       
        ctx.executeQueryAsync(Function.createDelegate(this, this.onUpdate),
               Function.createDelegate(this, this.onFail));


代码是写在test.js中.并在主页的webpart(Content Editor)引用
------解决方案--------------------
要等 sp.js 加载完成的,initialize是你要执行的函数名
ExecuteOrDelayUntilScriptLoaded(initialize, "sp.js");