Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript文件中有错误,但控制台中没有?_Javascript_Sharepoint_Spservices - Fatal编程技术网

javascript文件中有错误,但控制台中没有?

javascript文件中有错误,但控制台中没有?,javascript,sharepoint,spservices,Javascript,Sharepoint,Spservices,问题中的错误 Uncaught Error: The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested. 下面是代码,只是尝试获取列表的简单计数 var CustomAction = function(){ var clientConte

问题中的错误

Uncaught Error: The property or field has not been initialized. 
It has not been requested or the request has not been executed. 
It may need to be explicitly requested. 
下面是代码,只是尝试获取列表的简单计数

var CustomAction = function(){

    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web(); 
    this.oList = web.get_lists().getByTitle("Classification");

    // .load() tells CSOM to load the properties of this object
    // multiple .load()s can be stacked
    clientContext.load(oList);

    // now start the asynchronous call and perform all commands
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFailure));

    // method will exit here and onSuccess or OnFail will be called asynchronously

};

function onSuccess(sender, args) {
    alert('No of rows: ' + oList.get_itemCount());
};

function onFail(sender, args) {
    alert('Request failed.\n' + args.get_message() + '\n' + args.get_stackTrace());
};
错误发生在oList.get\u itemCount()上。发生这种情况的原因是什么?我尝试使用
$(文档).ready
$(窗口).onload
,但问题仍然存在。正如我所说,当我将其复制/粘贴到浏览器中时,它可以工作,但从文件中运行它却不能工作。

试试这个

var CustomAction=function(){
var clientContext=new SP.clientContext.get_current();
var web=clientContext.get_web();
this.oList=web.get_list().getByTitle(“分类”);
//.load()告诉CSOM加载此对象的属性
//可以堆叠多个.load()文件
clientContext.load(oList);
//现在启动异步调用并执行所有命令
clientContext.executeQueryAsync((函数(发送方,参数){alert('No of rows:'+oList.get_itemCount())}(this,this.onSuccess)),(函数(发送方,参数){alert('Request failed.\n'+args.get_message()+'\n'+args.get_stackTrace())}(this,this.OnFailed));
};

导致未捕获类型错误的原因:无法读取未定义的属性“PropertyHasNotBeenInInitialized”,但在控制台中运行也会导致原始错误而不是此错误。hmmm。。。顺便问一下,你是在用
ExecuteOrDelayUntilScriptLoaded
来包装你的函数吗?我是,
ExecuteOrDelayUntilScriptLoaded(CustomAction,“sp.js”)
可能是因为我必须说出文件的目录,还是没关系。哦,文件在文件夹中?我不确定。我建议在不同的列表/库上进行测试。我还建议你问这个问题,对不起,我说的没有多大意义。我的意思是“sp.js”可能没有正确指向,但它似乎并不关心这一点,所以这是无关紧要的。我已经张贴在那里,所以谢谢你!