为什么要将第一个索引值作为此代码

时间:2017-12-20 21:36:48

标签: jquery ajax

我想通过从数组中获取id和task id来使用ajax

please can try

每次点击都保存到数据库,但我不能 将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");

not getting the next index

2 个答案:

答案 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)

addBtn click

from django.contrib.auth.mixins import LoginRequiredMixin
from django.views import generic

class CreateGroup(LoginRequiredMixin, generic.CreateView):
    fields = ('name', 'description')
    model = Group