2015-04-22 103 views

回答

0

假設您的HTML具有以下內容 - 例如在內容編輯器Web部件:

<select id="MySelectId"> 
    <option value="" disabled selected>Select your option</option> 
</select> 

你的JavaScript可能看起來像這(使用jQuery爲了方便...):

$.ajax({ 
    url: "http://<DomainName>/<PathToWeb>/_api/web/lists/GetByTitle('<ListTitle>')/items", 
    type: "GET", 
    headers: { 
     "accept": "application/json;odata=verbose", 
    }, 
    success: function(data){ 
     $.each(data.d.results, function (key, value) { 
      $("#MySelectId").append($("<option></option>") 
          .val(value.ID) 
          .html(value.Title); 
     }); 
    }, 
    error: function(error){ 
     alert(JSON.stringify(error)); 
    } 
}); 

$.each回調可以用,但是你想的項目工作 - 例如填寫你的下拉列表等。

n.b.

?$select=FileLeafRef 

有在MS的TechNet和良好的更加examples on how to retrieve and work with SharePoint ListItems using REST:如果您還需要其他領域比ID或標題,你必須描述here包括他們在使用INTERNALNAME請求URL的末尾select語句documentation of the REST API在MSDN中。