Skip to content

Commit a49ca5d

Browse files
committed
feat: support array properties in v-view directive
re #80
1 parent 6ab7550 commit a49ca5d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Diff for: platform/nativescript/compiler/modules/view.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ function transformNode(el) {
66

77
if (attr) {
88
const attrName = attr.substr(1)
9+
let [arg, ...modifiers] = attrName.split('.')
10+
modifiers = modifiers.reduce((mods, mod) => {
11+
mods[mod] = true
12+
return mods
13+
}, {})
914
getAndRemoveAttr(el, attr)
10-
addDirective(el, 'view', `v-view:${attrName}`, '', attrName)
15+
addDirective(el, 'view', `v-view:${attrName}`, '', arg, modifiers)
1116
}
1217
}
1318

Diff for: platform/nativescript/runtime/directives/view.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
export default {
2-
inserted(el, { arg }) {
3-
const parent = el.parentNode
2+
inserted(el, { arg, modifiers }) {
3+
const parent = el.parentNode.nativeView
44

55
if (parent) {
6-
parent.setAttribute(arg, el.nativeView)
6+
if (modifiers.array) {
7+
parent[arg] = (parent[arg] || []).push(el.nativeView)
8+
} else {
9+
parent[arg] = el.nativeView
10+
}
711
}
812
}
913
}

0 commit comments

Comments
 (0)