2017-08-08 114 views
0

在我的JSON中,我有一个嵌套的Object数据作为数组和对象。它看起来像:JQuery Datatables使用嵌套对象数据过滤列(数组中的对象)

"contentVMlist":[ 
      { 
       "dbContID":3, 
       "dbContType":2, 
      }, 
      { 
       "dbContID":1, 
       "dbContType":1, 
      } 

"aoColumns: [ { "data": "contentVMlist.[ ].dbContType"} ]"我得到的数据到表。 它在表格列“2 1”中显示。

this.api().columns([9]).every(function() { 
var column = this; 
else if (column[0] == 9) { 
var select2 = $('<select> </select>') // the select is not so short i just shortened it now 
          .appendTo($('#dbContType')).on('change', function() { 
             var val = $.fn.dataTable.util.escapeRegex(
              $(this).val() 
             ); 
column.search(val ? '^' + val + '$' : '', true, false).draw(); 
}); 

如果 “contentVMlist” 只有1项,一切工作正常。但是,如果有2个或更多条目(如“1 3”或“1 3 2”),则无法将条目看作单个发生。它可以工作,如果选择是“1 3 2”,但用户只想要选择一个,然后所有类型都显示出来(如果有多个它也应该显示)

我怎样才能得到这样做? 我尝试了几个不同的东西,没有奏效。

+0

什么是你想达到什么目的?有选择列表中的所有dbContType值的列表? – balint

+0

@balint我有一个与dbContTypes的下拉过滤器。用户可以使用该过滤器 – Shaorandra

回答

0

我想最简单的方法是通过这个嵌套数组遍历:

var contentVMlist= []; // get a reference to the nested array 
jQuery.each(contentVMlist, function() { 
    console.log(this.dbContType); // check it 
    selectObj.appendTo("<option>"+this.dbContType+"</option>"); 
}); 
+0

来过滤数据表,以填充下拉菜单的权限?我有一个下拉选择选项“1”,“2”等。并过滤数据表。但只有那些只有一个控制类型的列。如果有两个contType(如“1 2”),它不会识别它们。对不起,如果我的问题不清楚 – Shaorandra