Ensure row key uniqueness for listview with sections

Summary: I encounter issues when using ListView with multiple Sections.
```
...
var ds = new ListView.DataSource({
  rowHasChanged           : (row1, row2) => row1 !== row2,
  sectionHeaderHasChanged : (s1, s2) => s1 !== s2
});
...
  getInitialState: function() {

    var sectionIDs = [0,1,2]
    var rowIDs = [
        [0,1,2],
        [0,1,2],
        [0,1,2]
    ]

    var dataBlob = [
        [blob0,blob1,blob2],
        [blob3,blob4,blob5],
        [blob6,blob7,blob8],
    ]

    return {
      dataSource : ds.cloneWithRowsAndSections(dataBlob, sectionIDs, rowIDs),
    };

```

the code above would throw error because of duplicate key, as ''sectionID0 + rowID0 === sectionID1 + rowID1'. And I have to do:
```
...
sectionIDs.map((id)=>{
  return id+'';
});

rowIDs.map((sec)=>{
  return sec,map((id)=>{
    return id+'';
  });
});
...
```

ListView with sections does not seem to be documented yet, so I am not sure if this is the intended behaviour or am I missing anything. Co
Closes https://github.com/facebook/react-native/pull/4082

Reviewed By: svcscm

Differential Revision: D2652028

Pulled By: mkonicek

fb-gh-sync-id: a9933bac1a1ae2d6cbc73a11ef6aefde6fcdb35f
This commit is contained in:
Qiao Liang 2015-11-13 08:12:43 -08:00 committed by facebook-github-bot-6
parent 50b8b00768
commit 993f15d2fe
1 changed files with 1 additions and 1 deletions

View File

@ -338,7 +338,7 @@ var ListView = React.createClass({
for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) { for (var rowIdx = 0; rowIdx < rowIDs.length; rowIdx++) {
var rowID = rowIDs[rowIdx]; var rowID = rowIDs[rowIdx];
var comboID = sectionID + rowID; var comboID = sectionID + '_' + rowID;
var shouldUpdateRow = rowCount >= this.state.prevRenderedRowsCount && var shouldUpdateRow = rowCount >= this.state.prevRenderedRowsCount &&
dataSource.rowShouldUpdate(sectionIdx, rowIdx); dataSource.rowShouldUpdate(sectionIdx, rowIdx);
var row = var row =