Bug During table binding in Buffalo and Solution
Buffalo version: Buffalo. Version = "2.0 ";
Problem reproduction:
Before calling buffalo. BIND. when BIND is bound to a table, jheight is 3, that is, the first row of the table header, the second row of the odd row style, the third row of the even row style, the first read data row is 3, no problem, however, if the number of rows returned for the second (and so on) is less than 2, for example, if there is only one row of data, the second row of the last data will not be deleted. Normally, a row of data should appear, however, there are two rows of data. The second row is the second row left over from the previous data. For example, when the number of returned data rows is 0, it is expected that no data rows will appear, however, the first two rows of the last data will appear. In general, when the jheight is 3, if the data is smaller than the two rows, the deletion will fail.
Analysis:
Read the original Code In the analysis of buffalo. the "bindtable: function (ELEM, value)" function in JS finds that its binding implementation is, delete all rows except the first two or three rows (when jheight is 3). The second and third rows of the original table are taken directly from the second and third rows, and the second and third rows are cloned based on parity, when we delete redundant rows first, Add rows with the same length as the returned data, and then fill in the data, the problem arises because the number of rows added is based on the length of the returned data, if the number of returned data rows is less than 2, for example, if there is only one row, all the rows of the original data will be deleted before binding. The first three rows are left, and then the data is filled in, because there is only one row of data, therefore, only the data in the first row (that is, the second row of the table) is updated, and the data in the second row (that is, the third row of the table) is not deleted, it is still the second row of the last data (that is, the third row of the table), and so on. When the returned data length is 0, the data of the last two rows will appear, the expected data behavior is not empty. Similarly, this problem occurs when jheight is 2.
Solution:
Try not to influence Source code Under the guidance of, I have taken a solution to hide unnecessary rows:
In bindtable: function (ELEM, value) in Buffalo. js (about 760 rows ):
1. If (jheight = 2) {// Add the following five rows
If (value. Length = 0) {// No value
Tbody. Rows [1]. style. Display = 'none ';
} Else {
Tbody. Rows [1]. style. Display = '';
}
......
2. If (jheight> = 3) {// Add the following 10 rows
If (value. Length = 0) {// No value
Tbody. Rows [1]. style. Display = 'none ';
Tbody. Rows [2]. style. Display = 'none ';
} Else if (value. Length = 1) {// a row of values exists.
Tbody. Rows [2]. style. Display = 'none ';
Tbody. Rows [1]. style. Display = '';
} Else {
Tbody. Rows [1]. style. Display = '';
Tbody. Rows [2]. style. Display = '';
}
......