我正在使用DataTable和Editor。如何计算另一个数据表中可用的值?我想计算(或有数字)table_02中值的可用频率,并将其显示在table_01的列数中。
table_01:
id | value | count
1|value_01|{count of value_01 in table_02}
2|value_02|{count of value_02 in table_02}
3|value_03|{count of value_03 in table_02}
4|value_04|{count of value_04 in table_02}
5|value_05|{count of value_05 in table_02}
table_02:
foreign_id | value
1|value_01
1|value_01
1|value_01
3|value_03
5|value_05
5|value_05
我可以计算table_02中的记录并将其显示在table_01中(见下文)。但我怎样才能过滤或仅计算例如使用' foreign_id'的值' 1' ?
table_01 = $('#table_01').DataTable( {
dom: "Blfrtip",
ajax: {
url: "source_01.php",
type: "POST",
data: function (d) {
d.selectUserID = userID;
} },
serverSide: true,
processing: true,
columns: [
{ data: "name" },
{ data: "id" },
{ data: "user_id", visible: false },
{ data: "count" ,
"render": function () {
var json = table_02.ajax.json().data;
return json.length;
}
}
],
...
consol.log(json.length):11
consol.log(json)是:
[Object { DT_RowId="row_1", table_01={...}, table_02={...}, more...},
Object { DT_RowId="row_47", table_01={...}, table_02={...}, more...},
...
Object { DT_RowId="row_41", table_01={...}, table_02={...}, more...},
Object { DT_RowId="row_46", table_01={...}, table_02={...}, more...}]
进一步......
table_01 = Object { value="Test 01", user_id="1"}
table_02 = Object { account_id="1", user_id="1", uid_foreign="1", more...}
是否可以循环遍历json并仅将对象渲染到例如table_02.uid_foreign = 1所以我可以对过滤后的结果做一个.length;