我有以下代码。但是下拉列表仍然为空,并且不会获取值。
$(document).ready(function () {
IconDrpDownBind();
});
function IconDrpDownBind() {
var listName = "AppIcon";
var url = _spPageContextInfo.webAbsoluteUrl;
getListItems(listName, url, function (data) {
var items = data.d.results;
console.log(items);
var inputElement ='<select id="drpicon"> <option value="">Select</option>';
// Add all the new items
for (var i = 0; i < items.length; i++) {
var itemId = items[i].Title,
itemVal = items[i].Title;
console.log(itemVal);
inputElement += "<option value= '" + itemId + '"selected>' + itemId + "</option>";
}
inputElement += '</select>';
$("#appicon").append(inputElement);
$("#drpicon").each(function () {
$('option', this).each(function () {
if ($(this).text() == 'Select') {
$(this).attr('selected', 'selected')
};
});
});
// assign the change event to provide an alert of the selected option value
$("#drpicon").on('change', function () {
alert($(this).val());
});
}, function (data) {
alert("Ooops, an error occurred. Please try again");
});
}
function getListItems(listName, siteurl, success, failure) {
$.ajax({
url: siteurl + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=FieldValuesAsText/FileRef&$expand=FieldValuesAsText",
//console.log(url);
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}
<tr>
<td class="sel">App Icon <span class="red">*</span></td>
<td>
<div class="tooltip" style="width: 208px;display:inline;">
<select name="AppIcon" id="appicon" class="half-width" name="Iconselect" type="text" id="iconselect" style="width: 215px;border:1px solid #a1a6af;height: 21px;"></select>
</div>
</td>
</tr>
我可以在控制台中看到如下所示的值 : {__元数据:{…},FileRef:“ / teams / GFCAnalyticsAppFarm / AppIcon / Distributor Stock Analysis.png”}
我需要从fileref中获取文件名并在下拉列表中显示。谁能帮我这个忙。 帮助我将文档从文档库绑定到下拉字段