我到目前为止成功将一个绑定到下拉列表但无法弄清楚如何添加下一个数据项(称为" text")
function loadCombo(context) {
list = context.get_web().get_lists().getByTitle('HRC');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<Query><Where></Where></Query>");
listItems = list.getItems(camlQuery);
context.load(listItems);
context.executeQueryAsync(appendData, loadFailed);
}
function appendData(sender, args) {
var enumerator = listItems.getEnumerator();
while (enumerator.moveNext()) {
var item = enumerator.get_current();
$("#country1").append($('<option></option>').val(item.get_id()).html(item.get_item('Title')));
}
}
function loadFailed(sender, args) {
alert('list failed to load: ' + args.get_message());
}
$(document).ready(function() {
var context = new SP.ClientContext.get_current();
loadCombo(context);
});
答案 0 :(得分:0)
我修改了你的代码。这个。
function loadCombo(context,listname) {
list = context.get_web().get_lists().getByTitle(listname);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<Query><Where></Where></Query>");
listItems = list.getItems(camlQuery);
context.load(listItems);
context.executeQueryAsync(appendData, loadFailed);
}
function appendData(sender, args) {
var enumerator = listItems.getEnumerator();
while (enumerator.moveNext()) {
var item = enumerator.get_current();
$("#country1").append($('<option></option>').val(item.get_item('Title')).html(item.get_item('Title')));
}
}
function loadFailed(sender, args) {
alert('list failed to load: ' + args.get_message());
}
$(document).ready(function() {
var context = new SP.ClientContext.get_current();
loadCombo(context,'HRC');
loadCombo(context,'XYZ');
});