Kendo UI & Javascript - 添加新记录时未获取数据

Kendo UI & Javascript - Data not fetch when Add New Record

大家好,

需要帮助,但不确定我做错了哪些部分。

当点击添加新记录时,我希望segmentActive字段禁用并且默认为单选按钮将在 YES 上选中。 我设法做到了。但是当我保存记录时,它不会将值“y”提取到我的数据库中。它将插入空值。

$("#grid").kendoGrid({
dataSource: dataSource,
height:400,
sortable: true,  
columns: [ 
    { field: "segmentActive", title:"STATUS", width: "120px" , editor: RadioSegmentActive,
      template: data => data.segmentActive == "y" ? "Yes" : "No" },

    { field: "marketSegmentName", title:"SEGMENT NAME", width: "120px" },

    //Button Name
    { command: [{ name: "edit", text: { edit: "Edit",
                                        update: "Submit", 
                                        cancel: "Cancel"} },
                { name: "destroy", text: "De-active" }], 
                  title: " ", width: "120px" },

],
editable: "inline",
edit: function(e) {
        if (e.model.isNew()) { // Went adding new record    
                $('input[name=segmentActive]').attr("disabled",true);  //disable column STATUS
                radio3.checked = true; // id="radio3" checked
        }
    },   
toolbar: [{ name: "create", text: "Add" }],
pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },          
});  //end of kendo grid

我的 RadioSegmentActive 函数

function RadioSegmentActive(container, options) {
var guid = kendo.guid();

    $('<input class="k-radio" id="radio3" name="segmentActive" type="radio" value="y" >').appendTo(container);
    $('<label class="k-radio-label" for="radio3">Yes</label>').appendTo(container);  //YES
    $('<br>').appendTo(container); 
    $('<input class="k-radio" id="radio4" name="segmentActive" type="radio" value="n" >').appendTo(container);
    $('<label class="k-radio-label" for="radio4">No</label>').appendTo(container);  //NO
}

提前谢谢你。

要检查值 console.log($('input[id=your_radio_button_id]:checked').val()); 然后在检查 window 中检查它是否有值。我猜不是因为它在数据库记录中为空。 您的编辑功能可以将更新值包含到隐藏的输入中。

edit: function(e) {
    if (e.model.isNew()) { // Went adding new record    
            $('input[name=segmentActive]').attr("disabled",true);  //disable column STATUS
            radio3.checked = true; // id="radio3" checked
            $("#hidden_input").val("y");
    }
}, 

将隐藏的输入放在收音机旁边

<input type="hidden" id="hidden_input" name="hidden_input">

同时更改您的后台代码以将隐藏字段与 Y 而不是无线电绑定。

这是 Kendo - 您需要更新它绑定的基础模型:

edit: function(e) {
    if (e.model.isNew()) { // Went adding new record    
            $('input[name=segmentActive]').attr("disabled",true);  //disable column STATUS
            radio3.checked = true; // id="radio3" checked
            // change the kendo model value
            e.model.set("segmentActive", "y");
    }
},