小编Dev*_*vTN的帖子

如何根据之前在 jQuery DataTables 中选择的值更新选择选项

我正在使用jQuery 数据表并应用单个列搜索(选择输入)

在表页脚上,我有一个引导选择,我可以在其中选择多个选项并过滤我的数据。

它工作正常,但是当我选择选项时,我希望根据之前选择的选项更新其他选择。

因此,在我的示例中,如果我选择伦敦和纽约办公室,我只想以名义查看位于伦敦和纽约的人员,而不是所有选项。

我创建了一个事件draw,我将在其中循环遍历每一列并获取选定的选项,select.val()然后我使用,table.column(idx, {search:'applied'}).data().unique()search:'applied数据表中的' 功能似乎不起作用。它给出的结果与我不应用搜索的结果相同。

请在我的演示下面找到详细说明。你能告诉我我的代码有什么问题吗?非常感谢。

$(document).ready(function() {

var table = $('#example').DataTable( {

initComplete: function () {

this.api().columns().every( function () {
//for each column I add bootstrap selectpicker to the footer
var column = this;
var select = $('<select class="form-control show-tick" data-container="body" data-header="Select option(s)" data-actions-box="true" data-live-search="true" title="All" data-selected-text-format="count > 0" multiple><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () { 
//everytime the options …
Run Code Online (Sandbox Code Playgroud)

javascript jquery datatables bootstrap-selectpicker

6
推荐指数
1
解决办法
553
查看次数

如何在 JavaScript/Jquery 中按数组分组

我有一个如下所示的数组

array1 = [{"month":"January","location":"CENTRAL","percentage":94},
{"month":"February","location":"CENTRAL","percentage":97},
{"month":"March","location":"CENTRAL","percentage":93},
{"month":"January","location":"NORTH","percentage":95},
{"month":"February","location":"NORTH","percentage":91},
{"month":"March","location":"NORTH","percentage":98}];
Run Code Online (Sandbox Code Playgroud)

我想格式化我的数组,如下所示

array2= [{
    location: "CENTRAL",
    January: 94,
    February: 97,
    March: 93},
    {
    location: "NORTH",
    January: 95,
    February: 91,
    March: 98}];
Run Code Online (Sandbox Code Playgroud)

我尝试使用按功能分组,如下所示

function groupBy(list, keyGetter) {
    const map = new Map();
    list.forEach((item) => {
        const key = keyGetter(item);
        if (!map.has(key)) {
            map.set(key, [item]);
        } else {
            map.get(key).push(item);
        }
    });
    return map;
}

const grouped = groupBy(array1, arr => arr.location);
console.log(grouped);
Run Code Online (Sandbox Code Playgroud)

但我没有得到相同的格式。有什么建议请我的想法中缺少什么?非常感谢。

javascript jquery

5
推荐指数
1
解决办法
4655
查看次数

如何在Javascript / Jquery中将键值对添加到数组

我有以下两个数组

var dataSource = [
{location: "France", January: 79, February: 81, March: 23},  
{location: "Germany", January: 98, February: 83},
{location: "Japan", January: 96, March: 11} ];

var Months = ["January","February","March"];
Run Code Online (Sandbox Code Playgroud)

我想遍历每个对象,dataSource并检查的每个对象中是否都Months存在的所有值dataSource。如果该值不存在,dataSource则将该值添加到dataSourcevalue = 100

例如:在德国,不存在月份“ March”,因此我需要按下键和值 March : 100

最后dataSource应该如下

var dataSource = [
{location: "France", January: 79, February: 81, March: 23},  
{location: "Germany", January: 98, February: 83, March: 100},
{location: "Japan", January: 96, February: 100, March: 11} ]; …
Run Code Online (Sandbox Code Playgroud)

javascript arrays jquery

3
推荐指数
1
解决办法
198
查看次数

如何用jQuery中的函数替换重复的代码块

我的页面上有多个选项卡,在每个选项卡上,我使用WebDataRocks插件声明一个数据透视表并向其添加一个事件。代码是重复的,因为唯一的区别是数据透视中的过滤器。

我想创建一个带参数的函数并在每个选项卡上调用它。我替换了当前代码:

var pivotAsia = new WebDataRocks({
    container: "wdr-component-1",
    toolbar: true,
    report: {
        dataSource: { data: getJSONData() },
        slice: {
            rows: [{ uniqueName: "continent" }],
            columns: [{ uniqueName: "Measures" }],
            measures: [{ uniqueName: "country", aggregation: "count" }],
            reportFilters: [{
                uniqueName: "continent",
                "filter": { "members": [ "continent.Asia" ] }  }]
        }
    }
});

$('#tab1').on( 'shown.bs.tab', function (e) { pivotAsia.refresh(); });
Run Code Online (Sandbox Code Playgroud)

和 :

function pivot (pivotName, component_id, continentFilter) {
var pivotName = new WebDataRocks({
    container: component_id,
    toolbar: true,
    report: { …
Run Code Online (Sandbox Code Playgroud)

javascript jquery function webdatarocks

2
推荐指数
1
解决办法
113
查看次数

如何在 &lt;script&gt; 标签内使用 PHP 变量

我在 URL 中传递 PHP 变量,所以我的页面链接如下所示www.example.com?redirect=neworders

根据$_GET['redirect']值,我在示例中创建页面内容input

然后在这一<script>部分中,我想根据PHP值调用带有参数的函数。

我当前的代码现在可以工作,但我相信这不是应该完成的正确方法,尽管我检查了多个线程并且通常答案是我提到的选项之一。

如果我做对了,有什么建议吗?我在代码中添加了注释以了解我的情况。非常感谢。

    <?php 
    
   //my url can be either www.example.com?redirect=neworders or www.example.com?redirect=deliveredorders

    switch($_GET['redirect']) {
      case 'neworders':
          $page = 'Backlog'; 
          break;
      case 'deliveredorders':  
          $page = 'Shipment';   
          break;
          }
    
    ?>
    
      <body>
    //based on $page value, I create the input value with a specific id
    <?php  
    if ( $page == 'neworders') { 
     echo '<input type="text" id="BacklogName" placeholder="enter order number">'; }
    elseif ( $page == 'deliveredorders') { 
     echo '<input type="text …
Run Code Online (Sandbox Code Playgroud)

javascript php jquery

1
推荐指数
1
解决办法
6886
查看次数