使用jquery索引删除过程时出现问题 [英] When remove course by using jquery index have problem

查看:71
本文介绍了使用jquery索引删除过程时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



从表格列表中删除任何课程html他在中心的位置或首先出现问题



数据库中的索引



详细信息



如果我有以下课程列表:



Delphi



Flash



Photoshop



如果我通过JQUERY删除按钮删除按钮然后点击保存按钮



删除flash和Photoshop



因为在jquery中使用删除功能删除课程有错



如果我删除php它没有任何问题,因为它是最后一项



建议



移除时使用地图功能但是怎么做



如果有任何解决方案而不使用地图否问题



i使用模式如下



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

}
}


模型视图中的
我的代码如下jquery



实际上我需要使用地图功能修改下面的代码如果有任何功能那就没关系



< pre> $(function(){
//使用下拉列表添加课程
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(){
//删除函数
。$(本).parent()父()删除();

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

//使用ajax
$ .ajax({
url:/ Employee / getcoursesbyempid,
数据:{x:$()在编辑视图中检索数据#hid)。val()},
成功:函数(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 ++;
});
}

})
});









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



我尝试过:



当使用jquery索引删除课程时遇到问题

解决方案

(function(){
//使用drop添加课程down
var index = 0;


(#CourseId)。change(function(){

var id =


(本).VAL();
var txt =


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

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


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++;
                    });
                }
 
            })
        });





Simple File Sharing and Storage.[^]

What I have tried:

when remove course by using jquery index have problem

解决方案

(function () { //add courses using drop down var index = 0;


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


(this).val(); var txt =


这篇关于使用jquery索引删除过程时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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