问题
I have a problem, I am a UX Designer and I am designing a Global Enterprise knowledge base. Data is stored everywhere. I need to be able to pull a list of directories & files from an online (hosted on Office 365) sharepoint repository and place it in a json file. Then allow the users to select the files and download them. My biggest need is to be able to get the list from the repository. I have been through the tons of documentation from MSDN, and now more confused than ever. I am strong in HTML5, CSS3, and kind-of weak in Javascript. All help is appreicated.
回答1:
If you want to retrieve folders and files in a JSON format, you can use jQuery's AJAX and REST to retrieve the data.
Your folders are document libraries, which are still SharePoint lists.
$.ajax({
url:"/_api/lists/",
headers: { "Accept": "application/json; odata=verbose"},
success:function(data) {
$.each(data.d.results, function(i, item) {
//here you can iterate through your items
data.d.results[i].FIELDNAME;
})
}
});
You will still need to use filters to select only your document libraries. Your best guess might be filtering by the content type.
Here is the ODATA documentation to filter your content:
http://www.odata.org/documentation/odata-version-2-0/uri-conventions/
Once you get the list you want, here you can query a specific list:
$.ajax({
url:"/_api/lists/getbytitle('LISTNAME')/items",
headers: { "Accept": "application/json; odata=verbose"},
success:function(data) {
$.each(data.d.results, function(i, item) {
//here you can iterate through your items
data.d.results[i].FIELDNAME;
})
}
});
来源:https://stackoverflow.com/questions/33131035/get-sharepoint-online-file-structure-into-json-file-using-javascript