Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e5577c

Browse filesBrowse 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
Copy full SHA for 7e5577c

File tree

1 file changed

+10
-1
lines changed
Filter options

1 file changed

+10
-1
lines changed

‎src/directives/public/for.js

Copy file name to clipboardExpand all lines: src/directives/public/for.js
+10-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.