2016-04-07 31 views
0

我正在爲SharePoint 2013構建一個圖像卷標器,並且出現此錯誤指向此行並且我不確定原因。我在學習html/js,所以我非常感謝所有的幫助。ReferenceError:未定義網站

這是代碼返回錯誤

var oList = website.get_lists().getByTitle(bannerListName);  

還有更多它的路線,但是這是什麼阻止它。

(function() 
{ 
/********************* User Defined Variables *************************************** 
**** Update the variables below to customize how the banner rotator works ***********/ 
var bannerListName = "Banner Rotator"; //the name of the list to pull the banner items from 
var interval = 7; //time to wait before showing the next picture (in seconds) 
var showPages = false; //change to false if you do not want to show the page numbers 

//if you know how to write CAML you can update this string 
//by default it looks for all items in the list, but you can change that here 
var query = '<View><Query><Where><Geq><FieldRef Name=\'ID\'/><Value Type=\'Number\'>1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>'; 
/***********************************************************************************/ 

//global variables 
var index = 0; 
var bannerList = []; 

$(document).ready(function() 
{ 
     // make sure the SharePoint script file 'sp.js' is loaded before code runs 
     SP.SOD.executeFunc('sp.js', 'SP.ClientContext',start); 
         }); 

function start() 
{ 
    ctx = SP.ClientContext.get_current(); 
    this.site = ctx.get_site(); 
    this.website = ctx.get_web(); 
    var oList = website.get_lists().getByTitle(bannerListName); 
    var camlQuery = new SP.CamlQuery(); 
    camlQuery.set_viewXml(query); 
    this.collListItem = oList.getItems(camlQuery); 
    ctx.load(collListItem); 
    this.ctx.executeQueryAsync(onQuerySucceeded, onQueryFailed); 

} 

回答

1

應該this.website並不僅僅是website

this.website = ctx.get_web(); //<-- you store it in this.website, not var website 
var oList = this.website.get_lists().getByTitle(bannerListName); 
+0

或者,有時我也喜歡簡單地創建一個變量,再利用相同的名稱。 'var website = this.website = ctx.get_web();'以便稍後在相同的環境中也可以使用'website'。 –

+0

這回答了我的問題:)但帶來了我的錯誤。我會盡力解決這些問題,現在我明白了發生了什麼!謝謝 – user6174153