성능상의 이유로 클라이언트에서 항목 수를 계산하는 것이 가장 좋습니다. 아래 코드와 같이 모든 목록에 카운터 기능을 호출 할 수 있습니다.
ExecuteOrDelayUntilScriptLoaded(CountListItems, "sp.js");
var clientContext = null;
var web = null;
function CountListItems()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var list = web.get_lists().getByTitle("mydocumnets");
var camlQuery = new SP.CamlQuery();
var qry = "<View><Query><Where></Where></Query></View>";
camlQuery.set_viewXml(qry);
this.listItems = list.getItems(camlQuery);
clientContext.load(listItems, 'Include(Title)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFailed));
}
function onSuccess(sender, args) {
alert(this.listItems.get_count());
}
function onFailed(sender, args) {
alert('request failed ');
}
감사합니다. Mahdi! 그러나 또 다른 도전에 직면 해있다. 나는 빈 곳 "div"(say : div class = "count")를 내 SharePoint 홈 페이지에서 출력하고 싶습니다. 이 일을 어떻게 할 수 있는지 안내해 주시겠습니까? – Simsumm
아, 네, onSuccess 함수에서 결과에 액세스 할 수 있습니다. 당신은 this.listItems 콜렉션에서 반복하고 html을 생성 한 다음 div에 배치 할 수 있습니다. 예를 들어 document.getElementById (elementID) .innerHTML = 'your hire html'; –
나는 이것을 시도했다 : function onSuccess (보낸 사람, args) { document.getElementById ('id name'). innerHTML = this.listItems.get_count(); } 그리고 "null의 InnerHTML '속성을 설정할 수 없습니다."라는 오류가 반환되었습니다. 이 일을하기 위해 내가해야 할 일에 대한 어떤 생각? 도와 주셔서 감사합니다. – Simsumm