mirror of
https://github.com/PuerkitoBio/goquery
synced 2025-10-06 01:07:06 +08:00
add support for negative indices in Slice(), with tests
This commit is contained in:
7
array.go
7
array.go
@@ -30,7 +30,12 @@ func (this *Selection) Eq(index int) *Selection {
|
||||
// Slice() reduces the set of matched elements to a subset specified by a range
|
||||
// of indices. At the moment, negative indices are not supported.
|
||||
func (this *Selection) Slice(start int, end int) *Selection {
|
||||
// TODO : Negative indices, like jQuery
|
||||
if start < 0 {
|
||||
start += len(this.Nodes)
|
||||
}
|
||||
if end < 0 {
|
||||
end += len(this.Nodes)
|
||||
}
|
||||
return pushStack(this, this.Nodes[start:end])
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user