Skip to content

Commit 7e5577c

Browse files
vprimachenkoyyx990803
authored andcommitted
allow optional (key,val) in arr syntax for v-for
optionally binding the iteration index (or key when iterating over an object) to a name to simplify work with nested `v-for`s
1 parent e879b8f commit 7e5577c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/directives/public/for.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ module.exports = {
1111
// support "item in items" syntax
1212
var inMatch = this.expression.match(/(.*) in (.*)/)
1313
if (inMatch) {
14-
this.alias = inMatch[1]
14+
var itMatch = inMatch[1].match(/\((.*),(.*)\)/)
15+
if (itMatch) {
16+
this.iterator = itMatch[1]
17+
this.alias = itMatch[2]
18+
} else {
19+
this.alias = inMatch[1]
20+
}
1521
this.expression = inMatch[2]
1622
}
1723

@@ -207,6 +213,9 @@ module.exports = {
207213
// avoid accidental fallback
208214
_.define(scope, '$key', null)
209215
}
216+
if (this.iterator) {
217+
_.defineReactive(scope, this.iterator, key || index)
218+
}
210219
var frag = this.factory.create(host, scope, this._frag)
211220
frag.forId = this.id
212221
this.cacheFrag(value, frag, index, key)

0 commit comments

Comments
 (0)