javascript - Function to retrieve items from a lists on SP -
i'm trying extract data sharepoint list create graphs , i'm in need of function extract items list can insert in parameters such name of list, , column names want extract. instantiate function: extractdata (listname, columntitle1, columntitle2)to extract different lists instantiating function.
function retrievelistitems() { var clientcontext = new sp.clientcontext(siteurl); var list1 = clientcontext.get_web().get_lists().getbytitle("list_name"); var camlquery = new sp.camlquery(); camlquery.set_viewxml('<view><query><where><geq><fieldref name=\'id\'/>' + '<value type=\'number\'>1</value></geq></where></query><rowlimit>200</rowlimit></view>'); this.colllistitem = list1.getitems(camlquery); clientcontext.load(colllistitem); clientcontext.executequeryasync(function.createdelegate(this, this.onquerysucceeded), function.createdelegate(this, this.onqueryfailed)); } function onquerysucceeded(sender, args) { var listitemenumerator = colllistitem.getenumerator(); while (listitemenumerator.movenext()) { var olistitem = listitemenumerator.get_current(); (var = 1; i<column1titles.length;i++){ myarray1[i].push(olistitem.get_item(column1titles[i])); } } graph("holder", global1[1], "high risk project", global1[2], "yes"); // instantiates graph, need extract data. } function onqueryfailed(sender, args) { alert('request failed. ' + args.get_message() + '\n' + args.get_stacktrace()); } // end of fail
your code not clear. trying push array ? right if have 3 columns (id, title, amount) , 3 rows in list, array this
[0] = 1; // id [1] = "some stuff"; // title [2] = 25; // amount [3] = 2; // id [4] = "something"; // title [5] = 15; // amount [6] = 3; // id [7] = "something else"; // title [8] = 36; // amount
i don't think makes sense, doesn't it? maybe want have 1 row = 1 row. array this:
[0][0] = 1; [0][1] = "some stuff"; // title [0][2] = 25; // amount [1][0] = 2; // id [1][1] = "something"; // title [1][2] = 15; // amount [2][0] = 3; // id [2][1] = "something else"; // title [2][2] = 36; // amount
if it's case, loop :
var myarray1=[],j=0; while (listitemenumerator.movenext()) { var olistitem = listitemenumerator.get_current(); myarray1[j]=[]; (var = 1; i<column1titles.length;i++){ myarray1[j].push(olistitem.get_item(column1titles[i])); } }
btw, microsoft api bad use ^^ created api : http://aymkdn.github.io/sharepointplus/ easy use. code library :
$sp().list("list_name").get({fields:column1titles, rowlimit:"200", where:"id >= 1"}, function(data) { var myarray1=[]; (var i=0, len=data.length; < len; i++) { myarray1[i]=[]; (var c=0; c < column1titles.length; c++) myarray1[i].push(data[i].getattribute(column1titles[c])); } graph("holder", global1[1], "high risk project", global1[2], "yes"); })
Comments
Post a Comment