1
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.
在這裏的錯誤是代碼,只是想獲得一個列表的簡單計數。在oList.get_itemCount()
發生
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());
};
該錯誤。這會發生什麼原因?我嘗試使用$(document).ready
和$(window).onload
,但問題仍然存在。所以就像我說的那樣,當我複製/粘貼到瀏覽器中但是從文件中運行它時,它起作用。
這導致'遺漏的類型錯誤:undefined'無法讀取屬性「propertyHasNotBeenInitialized」,但在控制檯運行也使原來的錯誤,而不是這一個。 – 2014-10-30 17:14:26
嗯...你是用'ExecuteOrDelayUntilScriptLoaded'來包裝你的函數嗎? – kei 2014-10-30 17:16:49
我是'ExecuteOrDelayUntilScriptLoaded(CustomAction,「sp.js」)'這可能是因爲我不得不說文件的目錄或者沒有關係。 – 2014-10-30 17:21:55