如何使用jquery映射索引以在删除时修复索引 [英] How to map index using jquery to repair indexes when remove

查看:66
本文介绍了如何使用jquery映射索引以在删除时修复索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Problem

when remove any course from table list html his position in center or first it make problem

in index in database

Details

IF I have list of courses as following :

Delphi

Flash

Photoshop

IF I remove flash by JQUERY remove button then click save button

it delete flash and Photoshop

because there are wrong in delete courses by using remove function in jquery

if i remove php it is working without any problem because it is last item

suggestion

using map function when remove but how to do that

if there are any solution for that without using map no problem

i use model as following







<pre>public class Cusomemp2
    {
        public List<EmployeeCourse> empcourses { get; set; }

    }
}



i用于编辑httppost




i use for edit httppost

<pre>var result = db.Employees
             .Where(p => p.Id == custom.Id)
             .Include(c => c.EmployeeCourses)
             .FirstOrDefault();
        if (custom.empcourses.Any())
        {
            foreach (var ec in result.EmployeeCourses.ToList())//to remove existing EmployeeCourses
            {
                db.EmployeeCourses.Remove(ec);
                db.SaveChanges();

            }
        }

        result.EmployeeCourses = custom.empcourses;
     db.SaveChanges();













in model view my code as following by jquery

actually i need to modify code below using map function if there are any function do that never mind







<pre>$(function () {
           //add courses using drop down
            var index = 0;
            $("#CourseId").change(function () {

                var id = $(this).val();
                var txt = $("#CourseId option:selected").text();

               $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + id + "'/></td><td>" + txt + "</td><td><input type='button' value='remove' class='r'</td></tr>")

                index++;

            });
            $("#tb").on("click", ".r", function () {
              // remove function
                $(this).parent().parent().remove();

                $(this).parent().prev().prev().remove();
             });

// retrieve data in edit view using ajax
            $.ajax({
                url: "/Employee/getcoursesbyempid",
                data:{x:$("#hid").val()},
                success: function (res) {
                    $.each(res, function (i, e) {

                          $("#tb").append("<tr><td><input type = 'hidden' name='empcourses[" + index + "].CourseId' value='" + e.Id + "'/></td><td>" + e.CourseName + "</td><td><input type='button' value='remove' class='r'</td></tr>")

                        index++;
                    });
                }

            })
        });







见下图,知道我需要什么

简单的文件共享和存储。 [ ^ ]



我尝试了什么:



当删除




see image below to know what i need
Simple File Sharing and Storage.[^]

What I have tried:

how to map index using jquery to repair indexes when remove

推荐答案

(function()时,如何使用jquery映射索引来修复索引{
//使用下拉列表添加课程
var index = 0;
(function () { //add courses using drop down var index = 0;


(#CourseId)。change(function(){

var id =
("#CourseId").change(function () { var id =


(this).val();
var txt =
(this).val(); var txt =


这篇关于如何使用jquery映射索引以在删除时修复索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆