这是我的import React from 'react';
import { Column, Table, SortDirection, SortIndicator } from 'react-virtualized';
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
import _ from 'underscore';
import 'react-virtualized/styles.css';
import { fakeJson } from './Data/fakeJson';
const datalist = fakeJson;
const list = datalist;
class TableComponent2 extends React.Component {
constructor(){
super();
this.state = {
sortBy: 'username',
sortDirection: SortDirection.DESC,
sortedList: list
}
}
sort({ sortBy, sortDirection }) {
console.log(list)
const tempList = _.sortBy(list, item => item[sortBy]);
console.log(tempList);
const sortedList = tempList.update(
list =>
sortDirection === SortDirection.DESC ? list.reverse() : list
);
this.setState({ sortBy, sortDirection, sortedList });
this.forceUpdateGrid;
}
render() {
return (
<AutoSizer disableHeight>
{({ width }) => (
<Table
headerHeight={20}
height={740}
rowCount={datalist.length}
rowGetter={({ index }) => this.state.sortedList[index]}
rowHeight={60}
width={width}
sort={this.sort}
sortBy={this.state.sortBy}
sortDirection={this.state.sortDirection}
>
<Column
dataKey='id'
width={200}
flexGrow={1}
label='ID'
/>
<Column
dataKey='name'
width={200}
flexGrow={1}
label='NAME'
/>
<Column
dataKey='username'
width={200}
flexGrow={1}
label='USERNAME'
/>
</Table>
)}
</AutoSizer>
);
}
}
export default TableComponent2;
数组:
group
这是我的array:4 [▼
0 => Fields {#7444 ▼
-id: 1
-name: "ID"
-unique_id: "6ab8c870ed"
-productgroup: PersistentCollection {#7448 ▶}
-type: Type {#7525 ▼
+__isInitialized__: true
-id: 2
-name: "hidden"
-unique_id: "5e1086c862"
-label: "hidden"
…2
}
}
1 => Fields {#7526 ▶}
2 => Fields {#7530 ▶}
3 => Fields {#7534 ▶}
]
数组:
column
我知道我的身份证是1:
array:3 [▼
0 => "id"
1 => "name"
2 => "type"
]
对于列键中的每个值,我想从$id = "1";
数组中打印出相应的值。
结果将是:
group
我试图用树枝实现这一目标
1
ID
hidden
错误是:
期望的姓名或号码。
注意:Symfony2 / Twig - getting array from dynamic array key并没有帮助我,因为它仅说明了如何使用像{% for key, value in column %}
{% for k, v in group %}
{{ v.[value] }};
{% endfor %}
{% endfor %}
或v[value]
这样的值,而没有说明像{{1 }}。
答案 0 :(得分:1)
您需要在代码中使用两个for
循环才能实现所需的功能,
{% for class in classes %}
if (optionValue == {{ class.id }}) {
{% for column in columns %}
var {{ column }} = '{{ attribute(class, column) }}';
{% endfor %}
}
{% endfor %}