【问题标题】:Refresh page call back the selected checkboxes Kendo in treeview刷新页面在树视图中回调选中的复选框剑道
【发布时间】:2019-12-02 07:54:49
【问题描述】:

在这里,我应该单击复选框,然后使用提交按钮 (AJAX) 将数据发送到数据库。单击提交按钮后,它将刷新页面,但所有选中的复选框都消失了。刷新页面后如何保留选中的复选框?有什么想法或指导吗?

AJAX

//AJAX call for button
    $("#primaryTextButton").kendoButton();
    var button = $("#primaryTextButton").data("kendoButton");
    button.bind("click", function(e) {

    var test = $("#dropdown").val()

    $.ajax({
        url: "../DesignationProgramTemplate/getTemplate.php",
        type: "post",
            data: {'id':test,'progid':array},
                success: function () {
                // you will get response from your php page (what you echo or print)                 
                    kendo.alert('Success'); // alert notification
                    //refresh
                    //location.reload("http://hq-global.winx.ehors.com:9280/ehors/HumanResource/EmployeeManagement/DesignationProgramTemplate/template.php");
                },
        });
    });

获取模板的 PHP

$employeeID = $_SESSION['employeeID'];
$propertyID = $_SESSION['propertyID'];
$id = $_POST['id'];
$progid = $_POST['progid'];

for($x=0; $x< sizeof($progid); $x++ )
{
    $array = array();   

$positionTemplateID = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplate"); 
$sqlAdd = "INSERT INTO tblHrsPositionProgramTemplate 
            SET positionTemplateID = '" . $positionTemplateID . "',
            programID = '" . $progid[$x] . "',
            hrsPositionID  = '" . $id . "',
            propertyID   = '" . $propertyID . "',
            employeeID  = '" . $employeeID . "',
            dateTimeEmployee = NOW() ";     

$ehorsObj->ExecuteData($sqlAdd, $ehorsObj->DEFAULT_PDO_CONNECTIONS);

$positionTemplateIDLog = $ehorsObj->EHORS_PK("tblHrsPositionProgramTemplateLog");   
$sqlAddLog = "INSERT INTO tblHrsPositionProgramTemplateLog 
            SET positionTemplateIDLog = '" . $positionTemplateIDLog . "',
            positionTemplateID = '" . $positionTemplateID . "',
            programID = '" . $progid[$x] . "',
            hrsPositionID  = '" . $id . "',
            propertyID   = '" . $propertyID . "',
            employeeID  = '" . $employeeID . "',
            dateTimeEmployee = NOW() ";     

$ehorsObj->ExecuteData($sqlAddLog, $ehorsObj->DEFAULT_PDO_CONNECTIONS);
}

复选框的功能

function checkedNodeIds(nodes, checkedNodes) {
  for (var i = 0; i < nodes.length; i++) {
    if (nodes[i].checked) {
      //checkedNodes.push(nodes[i].moduleID);
     // checkedNodes.push(nodes[i].groupID);
      checkedNodes.push(nodes[i].id);
    }

    if (nodes[i].hasChildren) {
      checkedNodeIds(nodes[i].children.view(), checkedNodes);
    }
  }

}

复选框检查

function toggleCheckAll() {
        var checkButtonValue = $("#chbAll").val();

        if(checkButtonValue == "Uncheck"){
          $("#AccountingTree .k-checkbox-wrapper input").prop("checked", true).trigger("change");
          $("#AdminSystemTree .k-checkbox-wrapper input").prop("checked", true).trigger("change");

          $("#chbAll").val("Check");
        } else {
          $("#AccountingTree .k-checkbox-wrapper input").prop("checked", false).trigger("change");
          $("#AdminSystemTree .k-checkbox-wrapper input").prop("checked", false).trigger("change");

          $("#chbAll").val("Uncheck");

        }

}

HTML

<div class="selectAll">
  <input type="checkbox" id="chbAll" value="Uncheck" class="k-checkbox" onchange="toggleCheckAll()" />

  <label class="k-checkbox-label" for="chbAll">Select All</label>

有人知道吗?

Output

【问题讨论】:

  • 一个想法,它与所有选定的会话链接
  • 你能举个例子吗?
  • 例如,当您发送到数据库时,您使用的是 PHP,在这种情况下,您可以将 nodes[i].id 保存在会话中,例如,如果您正在迭代复选框,如果您发现,添加到会话中,例如:SESSION['somesession'] .= nodes[i].id .';'
  • 我需要创建新会话吗?
  • 仅 1 次链接所有会话,例如以 ';' 分隔。 nodeid1;nodeid2...

标签: javascript php ajax checkbox


【解决方案1】:

这样你可以保存选中的复选框,记住它的 GET 方法。


<html>

<body>

<form method="get" action="">

    <input type="checkbox" name="vehicle1" value="Bike"> I have a bike<br>
    <input type="checkbox" name="vehicle2" value="Car"> I have a car<br>
    <input type="checkbox" name="vehicle3" value="Boat"> I have a boat<br>

    <input type="submit" name="submit">

</form>

</body>

    <script>

        var a = window.location.search.substr(1).split('&');
        console.log(a);
        function test(value, index){ a[index] = value.split("="); }
        function test2(value, index){ console.log(document.getElementsByName(value[0])); document.getElementsByName(value[0])[0].checked = true; }
        a.forEach(test);
        a.forEach(test2);

    </script>

</html>

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 2013-08-17
    相关资源
    最近更新 更多