我有一个数组,其中有另一个数组,我使用prime数据表来显示这个数组中的数据,请看下面的数组结构:
this.institutionalTimetable = [
{day: "Monday", entries: [{startTime: "132", endTime: "789", recess: true, subject: 'English', subjectGroup:'Maths' }, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}]},
{day: "Tuesday", entries: [{startTime: "132", endTime: "789", recess: true, subject: 'English', subjectGroup:'Maths' }, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}]},
{day: "Wednesday", entries: [{startTime: "132", endTime: "789", recess: true, subject: 'English', subjectGroup:'Maths' }, {startTime: "582", endTime: "634", recess: true, subject: 'English' , subjectGroup: 'Maths'}]}
]
所以我的表结构应该像第一列应该有day值 从第二列开始,基于条目数组中的元素,应该为所有行重复列
我应该如何根据主阵列内的数组重复<p-column>
?
这是我尝试的内容:
<p-dataTable [value]="institutionalTimetable" class="institutetable" >
<p-headerColumnGroup >
<p-row>
<p-column header="Week Days"></p-column>
<p-column header="Time table" [colspan]="10"></p-column>
</p-row>
</p-headerColumnGroup>
<p-column field="day"></p-column>
<p-column field="entries" *ngFor="let entrys of entries">
<ng-template let-col let-entryData="rowData" pTemplate="body">
<span>{{ entrys.startTime }}</span>
</ng-template>
</p-column>
</p-dataTable>
&#13;
答案 0 :(得分:0)
我希望我很了解你的需要。
如果我是你,我会做的是通过循环每天和 institutionalTimetable 的每个条目重新创建一个数组。
然后,你只需要一个简单的<p-dataTable [value]="institutionalTimetable2" class="institutetable" >
<p-headerColumnGroup >
<p-row>
<p-column header="Week Days"></p-column>
<p-column header="Time table" [colspan]="5"></p-column>
</p-row>
</p-headerColumnGroup>
<p-column field="day"></p-column>
<p-column field="startTime"></p-column>
<p-column field="endTime"></p-column>
<p-column field="recess"></p-column>
<p-column field="subject"></p-column>
<p-column field="subjectGroup"></p-column>
</p-dataTable>
:
import java.io.InputStream;
import java.util.Arrays;
/**
* This code demonstrates non blocking read from standard input using separate
* thread for reading.
*/
public class NonBlockingRead {
// Holder for temporary store of read(InputStream is) value
private static String threadValue = "";
public static void main(String[] args) throws InterruptedException {
NonBlockingRead test = new NonBlockingRead();
while (true) {
String tmp = test.read(System.in, 100);
if (tmp.length() > 0)
System.out.println(tmp);
Thread.sleep(1000);
}
}
/**
* Non blocking read from input stream using controlled thread
*
* @param is
* — InputStream to read
* @param timeout
* — timeout, should not be less that 10
* @return
*/
String read(final InputStream is, int timeout) {
// Start reading bytes from stream in separate thread
Thread thread = new Thread() {
public void run() {
byte[] buffer = new byte[1024]; // read buffer
byte[] readBytes = new byte[0]; // holder of actually read bytes
try {
Thread.sleep(5);
// Read available bytes from stream
int size = is.read(buffer);
if (size > 0)
readBytes = Arrays.copyOf(buffer, size);
// and save read value in static variable
setValue(new String(readBytes, "UTF-8"));
} catch (Exception e) {
System.err.println("Error reading input stream\nStack trace:\n" + e.getStackTrace());
}
}
};
thread.start(); // Start thread
try {
thread.join(timeout); // and join it with specified timeout
} catch (InterruptedException e) {
System.err.println("Data were note read in " + timeout + " ms");
}
return getValue();
}
private synchronized void setValue(String value) {
threadValue = value;
}
private synchronized String getValue() {
String tmp = new String(threadValue);
setValue("");
return tmp;
}
}
查看我的Plunker