我想通过从数组中获取id和task id来使用ajax
每次点击都保存到数据库,但我不能 将id转换为json数据
function add()
{
var selectId = $("#pickData");
var selected = new Array();
var objResult = [];
selected = selectId.find(" :selected").toArray();
重复代码块
var seciliDizin = selectId.find(" :selected");
seciliDizin.each(function () {
objResult.push({
userId: seciliDizin.data('id'),
taskId: seciliDizin.data('tid')
});
});
console.log(selected);
console.log(objResult);
debugger;
$.ajax({
type: "Post",
url: '@Url.Action("AppointToAddResult", "GorevIslemleri")',
// data: { tid: taskId, : id, : userId },
dataType: "json",
success: function (list) {
debugger;
if (list.taskId !== 0 && list.ıserId !== 0) {
// document.getElementById('taskEditModal').reset();
//$("#warningModal .modal-body").html("<p>Kayıt Yapıldı</p>");
// $("#warningModal").modal();
// $("#taskEditModal").modal("hide");
}
}
});
}
尝试但没有工作
selectId.find("option :selected");
答案 0 :(得分:1)
https://jsfiddle.net/sudarpochong/hvnjnm6o/3/
$(this)
内使用this
代替each
获取数据text()
代替text
<强>代码强>
this.getValues = function() {
var objResult = [];
this.find("#pickListResult option").each(function() {
// console.log("getValues", this);
objResult.push({
id: $(this).data("id"),
tid: $(this).data("tid"),
text: $(this).text()
});
});
return objResult;
};
答案 1 :(得分:0)
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views import generic
class CreateGroup(LoginRequiredMixin, generic.CreateView):
fields = ('name', 'description')
model = Group