0

原谅一大段代码,但我被卡住了,对此我真的筋疲力尽了......

所以我正在加载一些内容,然后显示一个对话框。根据您按下的按钮,我会做几件事。我的不一致似乎在“保存计划”和“取消发送”块之间

此代码在两个块中是相同的

var dt = $(this).find("input[type=text]").val();
var id = $(this).find("input[type=text]").attr("id");
var CustomObjectKey = id.split("_")[1];
var alt = $(this).find("input[type=text]").attr("alt");

然而,在取消发送块中,id 是未定义的,因此拆分正在爆炸。

谁能告诉我我做错了什么?

$("#ActionContainer").load(wsUrl, { Function:"BuildScheduleDialog", ArticleID:ArticleID}, function(){
                var Subject = $(this).find("#hdnSubject").val();
                $("#ActionContainer").dialog({
                    title: "Edit Schedule: " + ArticleTitle,
                    height: 'auto',
                    width: 'auto',
                    modal: true,
                    buttons: {
                        'Cancel': function() {

                            $(this).dialog('close');
                        },
                        'Save Schedule': function() {
                            var that = $(this);
                            var table = $("#tblSchedule");
                            var parameterArray = [];

                            //loop each row of the Schedule table to get the parameters
                            $(table).find("tbody>tr").not(':first').each(function () {
                                var dt = $(this).find("input[type=text]").val();
                                var id = $(this).find("input[type=text]").attr("id");
                                var CustomObjectKey = id.split("_")[1];
                                var alt = $(this).find("input[type=text]").attr("alt");

                                //alert(dt + " " + id + " " + CustomObjectKey + " " + alt);
                                if(dt != "" && alt === "")
                                {
                                    parameterArray.push({Region: $(this).find("#spRegion").text(), Date: dt, ArticleTitle: ArticleTitle ,ArticleID: ArticleID, PublicationTypeID: PublicationTypeID, CustomObjectKey: CustomObjectKey, Subject: Subject});
                                }
                            });

                            if(parameterArray.length > 0)
                            {
                                ShowWaitIcon();
                                $("#results").load(wsUrl, { Function:"Schedule", Action: "Edit", Items: JSON.stringify(parameterArray)}, function(){
                                    $("#results").fadeIn(1000);
                                    $('#results').delay(3000).fadeOut(3000);
                                    $(that).dialog('close');
                                    LoadMainTable();
                                });
                            }
                            else
                            {
                                alert("Please select at least one Item to Schedule");
                            }

                        },
                         'Cancel Send': function() {
                         if(confirm("Are you sure you want to cancel this entire send?"))
                         {
                             var that = $(this);
                             var table = $("#tblSchedule");
                             var parameterArray = [];

                             var status = "";
                             $(table).find("tbody>tr").each(function () {                                    
                                var dt = $(this).find("input[type=text]").val();                                     
                                 var id = $(this).find("input[type=text]").attr("id");                                     
                                 var CustomObjectKey = id.split("_")[1];                                     
                                 var alt = $(this).find("input[type=text]").attr("alt");                                                                         
                                parameterArray.push({Region: $(this).find("span").text(), Date: dt, ArticleTitle: ArticleTitle ,ArticleID: ArticleID, PublicationTypeID: PublicationTypeID, CustomObjectKey:CustomObjectKey});
                             });

                             /*ShowWaitIcon();
                             $("#results").load(wsUrl, { Function:"CancelAllSchedule", Items: JSON.stringify(parameterArray)}, function(){
                                $("#results").fadeIn(1000);
                                $('#results').delay(3000).fadeOut(3000);
                                $(that).dialog('close');
                                LoadMainTable();
                             });

                         */}
                        }
                    },open: function(event, ui){
                        $(".datePicker", "#ActionContainer").datetimepicker({
                            timeFormat: 'hh:mm tt',
                            showTimezone: true
                        });
                        BindCheckboxes();
                    }
                });
            });
4

1 回答 1

0

尝试用$(table).findjust 替换下面table.find(因为你已经声明了table = $("#tblSchedule")

                         var table = $("#tblSchedule");
                         var parameterArray = [];

                         var status = "";
                         $(table).find("tbody>tr").each(function () {                                    
                            var dt = $(this).find("input[type=text]").val();                                     
                             var id = $(this).find("input[type=text]").attr("id");                                     
                             var CustomObjectKey = id.split("_")[1];                                     
                             var alt = $(this).find("input[type=text]").attr("alt");                                                                         
                            parameterArray.push({Region: $(this).find("span").text(), Date: dt, ArticleTitle: ArticleTitle ,ArticleID: ArticleID, PublicationTypeID: PublicationTypeID, CustomObjectKey:CustomObjectKey});
                         });

此外,如果您尝试从 中选择每个tr$("#tblSchedule")可能$("#tblSchedule").find("tr")是更好的选择器。

于 2013-02-08T01:41:40.587 回答