RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 829251
Accepted
Nick
Nick
Asked:2020-05-17 20:06:14 +0000 UTC2020-05-17 20:06:14 +0000 UTC 2020-05-17 20:06:14 +0000 UTC

为什么需要双击选择表格中的一行?

  • 772

大家好。我有一个页面,上面有一个包含客户姓名的下拉列表。当一个客户被选中时,一个表格被动态加载(使用 ajax),其中包含该客户的配置。

在此处输入图像描述

通过单击相应的行进行配置的选择: 在此处输入图像描述

当表格超过 5 行时,它将滚动,即 有一个滑块(表中的最大行数是五)。当表格超过五行时,它会更改其样式:

在此处输入图像描述

为什么会发生这种情况我不知道。如果我们单击表格中的任何行(表格超过 5 行)或通常在页面上的任何区域,首先下拉列表将散焦,然后(或更早)表格将更改其样式: 在此处输入图像描述

因此,要在超过 5 行的表格中选择配置,您必须双击。(需要一键选择)

js代码:

function changeCustomerName(customerName) {
        getConfigurationsForSpecifiedCustomer(customerName);
    }

function createTableForConfiguration(data){
    fillTable(data);
    $('#configurationTable').show();
}

function fillTable(data){
    $('#tableBody').empty();
    data.forEach(function(item) {
        $('#tableBody').append(
            '<tr>' +
            '<td style="display:none">' +
            item.id +
            '</td>' +
            '<td>' +
            item.name +
            '</td>' +
            '</tr>'
        )
    });
}

function getConfigurationsForSpecifiedCustomer(customerName) {
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "/getConfigurationsForSpecifiedCustomer",
        data: JSON.stringify(customerName),
        dataType: 'json',
        success: function(response) {
            createTableForConfiguration(response);
        },
        error: function(e){
            // alert('Error from getConfigurationsForSpecifiedCustomer' + e);
            console.log('Error from getConfigurationsForSpecifiedCustomer' + e);
            $('#configurationTable').hide();
        }
    });
}

$(document).ready(function(){

$('#secondTable').on("click", '#tableBody tr', function(){
    var selected = $(this).hasClass("highlight");
    $("#tableBody tr").removeClass("highlight");
    if(!selected)
        $(this).addClass("highlight");
    $("[name='configuration']").val($(this).context.children[0].innerText);
});

});

html:

 <div id="table" class="scroll">
            <table id="secondTable" class ="tableBorder">
                <thead>
                <tr>
                    <th style="display:none">id</th>
                    <th>Configuration Name</th>
                    <th>Product Name</th>
                    <th>Product Version</th>
                    <th>Solution Build</th>
                    <th>Customer Name</th>
                    <th>GP Code</th>
                    <th>Oracle DB Version</th>
                    <th>Configuration Version</th>
                </tr>
                </thead>
                <tbody id="tableBody">
                </tbody>
            </table>
        </div>

风格:

body {
    font-size: 1em;
}

h1 {
    font-size: 2em;
}

table.tableBorder {
    width: 100%;
    border: 1px solid black;
    border-collapse: collapse;
}

table.tableBorder th, table.tableBorder td {
    padding: 4px 3px;
    border: 1px solid black;
}

.scroll{
    width: 100%;
    max-height: 150px;
    overflow: auto;
}

.highlight { background-color: grey; }

阿贾克斯回应:

在此处输入图像描述

Ajax 响应返回一个列表。配置是一个 POJO 类。我注意到,如果您传递一个列表,那么一切正常,表格的样式不会改变,也不需要双击。

响应 ajax 调用的控制器:

@RequestMapping(value = "/getConfigurationsForSpecifiedCustomer", method=RequestMethod.POST)
public @ResponseBody List<Configuration> getConfigurationsForSpecifiedCustomer(@RequestBody String customer) {
    if("".equals(customer))
        return null;
    return configurationService.getConfigurationsOfCustomer(customer.replaceAll("\"", ""));
}

配置类:

@Builder
@AllArgsConstructor
@Data
public class Configuration {
    private final int version;
    private final UUID id;
    private final String name;
    private final String author;
    private final String comment;
    private Map<String, String> customerInfo;
    private Collection<Rule> rules;
    private Collection<WhiteListItem> whiteList;
}

jQuery版本^

/static/js/jquery-2.1.1.min.js

这里有什么问题我无法理解,大脑拒绝。我会很高兴你的建议。

javascript
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    Stepan Kasyanenko
    2020-05-17T20:25:41Z2020-05-17T20:25:41Z

    看起来像出现了一个滚动,因此,表格的宽度发生了变化,因此,表格的显示也发生了变化。

    尝试将表格宽度设置为更大的尺寸。

    • 1

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    是否可以在 C++ 中继承类 <---> 结构?

    • 2 个回答
  • Marko Smith

    这种神经网络架构适合文本分类吗?

    • 1 个回答
  • Marko Smith

    为什么分配的工作方式不同?

    • 3 个回答
  • Marko Smith

    控制台中的光标坐标

    • 1 个回答
  • Marko Smith

    如何在 C++ 中删除类的实例?

    • 4 个回答
  • Marko Smith

    点是否属于线段的问题

    • 2 个回答
  • Marko Smith

    json结构错误

    • 1 个回答
  • Marko Smith

    ServiceWorker 中的“获取”事件

    • 1 个回答
  • Marko Smith

    c ++控制台应用程序exe文件[重复]

    • 1 个回答
  • Marko Smith

    按多列从sql表中选择

    • 1 个回答
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Suvitruf - Andrei Apanasik 什么是空? 2020-08-21 01:48:09 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5