Skip to content

Instantly share code, notes, and snippets.

@limscoder
Last active November 19, 2017 17:04
Show Gist options
  • Select an option

  • Save limscoder/ea96bd30b4f761a0f690548bff442bc3 to your computer and use it in GitHub Desktop.

Select an option

Save limscoder/ea96bd30b4f761a0f690548bff442bc3 to your computer and use it in GitHub Desktop.
D3 data selection
// html:
// <ul>
// <li></li>
// <li></li>
// </ul>
const users = [{
id: 1,
name: 'Nancy',
role: 'person'
}, {
id: 2,
name: 'Bart',
role: 'cartoon'
}, {
id: 3,
name: 'Maggie',
role: 'cartoon'
}];
const selection = d3.select('ul.app-user-list')
.selectAll('li.app-user')
.data(users);
// prints "2"
// Nancy and Bart datums were matched to the two "li" elements in the document.
console.log(selection.size())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment