Javascript 将选定值与另一个列表中的值进行比较
我想做的是将下拉列表中选择的值涂上焦油,以显示数据结果列表。在中,您可以使用以下下拉列表:Javascript 将选定值与另一个列表中的值进行比较,javascript,jquery,sharepoint-2013,Javascript,Jquery,Sharepoint 2013,我想做的是将下拉列表中选择的值涂上焦油,以显示数据结果列表。在中,您可以使用以下下拉列表: var body = String.format("{{'__metadata':{{'type':'{0}'}},'Nombre':'{1}','Empresa':'{2}','Correo':'{3}','Area':'{4}','Telefono':'{5}','Mensaje':'{6}'}}", GetItemTypeForListName('Contacto'), jQuery("#tx
var body = String.format("{{'__metadata':{{'type':'{0}'}},'Nombre':'{1}','Empresa':'{2}','Correo':'{3}','Area':'{4}','Telefono':'{5}','Mensaje':'{6}'}}",
GetItemTypeForListName('Contacto'), jQuery("#txtNombreCompleto2").val(), jQuery("#txtNombreEmpresa").val(),jQuery("#exampleInputEmail2").val(),$('#dropOficina2').val(),jQuery("#txtTelefono2").val(),jQuery("#txtMensaje2").val());
My$('dropOficina2').val()有3个值:“Finanzas”、“Operacion”和“Recursos Humanos”
所以,根据选择的值,它会将一个值返回到主体中
我得到的标题和科雷奥列表如下:
var query = "?$select=Title,Correo";
$.ajax({
url: url + "/_api/web/lists/getbytitle('ContactosCorreos')/items" + query,
method: 'GET',
headers: { "Accept": "application/json; odata=verbose" },
success: function(data) {
for (var i = 0; i < data.d.results.length; i++) {
console.log("Title: "+data.d.results[i].Title);
console.log("Correo: "+data.d.results[i].Correo); }
}});
我尝试了这些:但它总是给我发送“标题”和“科雷奥”数组
var selectedvalue=$(“#dropOficina2”).val();
var to=“”;
var query=“?$select=Title,Correo”;
$.ajax({
url:url+“/”api/web/lists/getbytitle('ContactosCorreos')/items“+查询,
方法:“GET”,
标题:{“Accept”:“application/json;odata=verbose”},
成功:功能(数据){
对于(变量i=0;i
设置“to”变量的条件语句应进入for循环:
var selectedvalue = $("#dropOficina2").val();
var to = "";
var query = "?$select=Title,Correo";
$.ajax({
url : url + "/_api/web/lists/getbytitle('ContactosCorreos')/items" + query,
method : 'GET',
headers : {
"Accept" : "application/json; odata=verbose"
},
success : function (data) {
for (var i = 0; i < data.d.results.length; i++) {
console.log("Title: " + data.d.results[i].Title);
console.log("Correo: " + data.d.results[i].Correo);
// move conditional statement into for loop
// check the value of item's title you really only need
//to have one condition if your Titles are unique
if (selectedvalue === data.d.results[i].Title) {
// access the results by index, just like you
//did in the console.log
to = data.d.results[i].Correo;
}
}
}
});
如果标题是唯一的,则只能得到一个Correo结果。设置“to”变量的条件语句应进入for循环:
var selectedvalue = $("#dropOficina2").val();
var to = "";
var query = "?$select=Title,Correo";
$.ajax({
url : url + "/_api/web/lists/getbytitle('ContactosCorreos')/items" + query,
method : 'GET',
headers : {
"Accept" : "application/json; odata=verbose"
},
success : function (data) {
for (var i = 0; i < data.d.results.length; i++) {
console.log("Title: " + data.d.results[i].Title);
console.log("Correo: " + data.d.results[i].Correo);
// move conditional statement into for loop
// check the value of item's title you really only need
//to have one condition if your Titles are unique
if (selectedvalue === data.d.results[i].Title) {
// access the results by index, just like you
//did in the console.log
to = data.d.results[i].Correo;
}
}
}
});
如果标题是唯一的,那么您只能得到一个Correo结果
var selectedvalue = $("#dropOficina2").val();
var to = "";
var query = "?$select=Title,Correo";
$.ajax({
url : url + "/_api/web/lists/getbytitle('ContactosCorreos')/items" + query,
method : 'GET',
headers : {
"Accept" : "application/json; odata=verbose"
},
success : function (data) {
for (var i = 0; i < data.d.results.length; i++) {
console.log("Title: " + data.d.results[i].Title);
console.log("Correo: " + data.d.results[i].Correo);
// move conditional statement into for loop
// check the value of item's title you really only need
//to have one condition if your Titles are unique
if (selectedvalue === data.d.results[i].Title) {
// access the results by index, just like you
//did in the console.log
to = data.d.results[i].Correo;
}
}
}
});
var query = "?$select=Correo&$filter=Title eq '" + selectedvalue +"'";