简体   繁体   English

我需要根据另一个 API 的值检查一个 API 中的预加载复选框,我该怎么做?

[英]I need to Check the preloaded checkbox from one API based on the Value of Another API, How can I do that?

      HTML;
    
                <!DOCTYPE html>
                <html lang="en">
                <head>
                    <meta charset="UTF-8">
                    <meta http-equiv="X-UA-Compatible" content="IE=edge">
                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
                    <title>Document</title>
                          
                </head>
                <body>
                    <table id="Table1" class="table table-bordered table-hover">
                        <thead>
    <tr>
    <th>List</th>
    <th>Push Notification&nbsp;&nbsp;&nbsp;<input type='checkbox'  name='all_push' id='all_push' class='all_push' /></th>
    <th>SMS&nbsp;&nbsp;&nbsp;<input type='checkbox' name='all_sms' id='all_sms' class='all_sms' /></th>
    <th>Call&nbsp;&nbsp;&nbsp;<input type='checkbox' name='all_call' id='all_call' class='all_call' /></th>
    <th>Email&nbsp;&nbsp;&nbsp;<input type='checkbox' name='all_email' id='all_email' class='all_email' /></th>
    </tr>            
    
    </thead>
    <tbody>
    <tbody>
    </table>
    </body>
    </html>
    
    JS;
            
    Here I have to do two things, first I have to fetch the checkboxes which I have access, from one API . Then I have to check the checkboxes based of another API value .
            
    Here I fetched the check boxes from the API,
            
    function getlist(t, e) {
                    
    $.ajax({
    type: "GET",
    url: base_api_url,
    dataType: "json",
                        success: function (t) {         
                            
                            t.length > 0 ? $.each(t, function (t, a) {
                                    var push_notif_checked = push_notif_disabled = '';
                                    var sms_checked = sms_disabled = '';
                                    var call_checked = call_disabled = '';
                                    var email_checked = email_disabled = '';
                                    if(a.push_notification == 'No') {
                                        push_notif_disabled = 'disabled';
                                    }
                                    if(a.sms == 'No') {
                                        sms_disabled = 'disabled';
                                    }
                                    if(a.call == 'No') {
                                        call_disabled = 'disabled';
                                    }
                                    if(a.email == 'No') {
                                        email_disabled = 'disabled';
                                    }
                                    
          e += "<tr class='extra_rows'><td>" Mobile "</td><td><input type='checkbox'id='push_notification' class='push_notification'/></td><td><input type='checkbox'  class='sms' /></td><td><input type='checkbox'  class='call' /></td><td><input type='checkbox'  class='email' /></td></tr>"
                                }) :e="<tr class='extra_rows'><td colspan='2'>No data found.</td></tr>",
                                $("#Table1").append(e)
                        },
                        error: function () {
                            toastr.error("Something went wrong ")
                        }
                    })
                };

    

Now I have to make another Ajax to check the Checkboxes based on Json Result,现在我必须制作另一个 Ajax 来检查基于 Json 结果的复选框,

For Example Consider my JSON result format as follows,例如考虑我的 JSON 结果格式如下,

{ "Phone_list":"no need", "Push_notif":"Yes", "Sms_notif":"No", "Call_notif":"Yes", "Email_notif":"No" }, { "Phone_list":"不需要", "Push_notif":"是", "Sms_notif":"否", "Call_notif":"是", "Email_notif":"否" },

I need to Check the Checkboxes of Push notification if the JSON value of Push_notif is "Yes", Likewise how can I do it for SMS,Call,Email based on JSON result shown in above row by row,I have stuck in this for a while, can somebody help me?如果 Push_notif 的 JSON 值为“是”,我需要检查推送通知的复选框,同样我该如何为 SMS、Call、Email 执行此操作,基于 Z0ECD11C1D7A287401D148A23BBD7A2 的结果如上所示同时,有人可以帮助我吗?

For checking the checkbox you need to use this in jquery要检查复选框,您需要在 jquery 中使用它

.checkboxClass => this is class name of checkbox .checkboxClass => 这是 class 复选框的名称

$('.checkboxClass').prop('checked', true); $('.checkboxClass').prop('checked', true);

for un check $('.checkboxClass').prop('checked', false); for un check $('.checkboxClass').prop('checked', false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要保留对预加载图像的引用,还是可以对其进行垃圾回收? - Do I need to keep a reference to preloaded images or can they be garbage collected? 如何检查基于文本的复选框? - How can I check the checkbox based on the text? 如何在Redux中使用一个API中的ID从另一个API获取信息? - How do I use the ID in one API to get info from another API in Redux? 如何从这个 api 中选择我需要的数据? - How do I select the data I need from this api? 如何从此 API 中获取值? - How do I get the value from this API? 选中另一个复选框后,如何检查该复选框? [JavaScript的] - How can I check a checkbox when another checkbox is checked? [JavaScript] JavaScript Web Speech API:我如何需要该值? - JavaScript Web Speech API: How can I need the value? 我需要一个可以从 html 检查特定复选框的 javascript 命令 - I need a javascript command that can check a speciffic checkbox from html OpenWeather API,如何将响应从一个响应传递到另一个调用? - OpenWeather API, How do I pass in response from one response to another call? 如何使用承诺执行函数并通过 API 调用多次检查其值并使用该值执行另一个函数? - How can I execute a function with promises and check its value multiple times by API call and execute another function with the value?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM