Skip to content

Commit 3114cca

Browse files
committed
fix: allow using for attribute in custom components
1 parent b7ef82c commit 3114cca

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

platform/nativescript/compiler/modules/list-view.js renamed to platform/nativescript/compiler/modules/for.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { getAndRemoveAttr, addRawAttr } from 'compiler/helpers'
2-
import { normalizeElementName } from '../../element-registry'
3-
import { parseFor } from 'compiler/parser/index'
4-
import { warn } from 'core/util/debug'
1+
import {getAndRemoveAttr, addRawAttr} from 'compiler/helpers'
2+
import {normalizeElementName} from '../../element-registry'
3+
import {parseFor} from 'compiler/parser/index'
4+
import {warn} from 'core/util/debug'
55

66
function preTransformNode(el) {
7-
if (normalizeElementName(el.tag) !== 'listview') {
8-
return
9-
}
7+
let vfor
108

11-
const vfor = getAndRemoveAttr(el, 'v-for')
12-
delete el.attrsMap['v-for']
13-
if (process.env.NODE_ENV !== 'production' && vfor) {
14-
warn(
15-
`The v-for directive is not supported on a ${el.tag}, ` +
9+
if (normalizeElementName(el.tag) === 'listview') {
10+
vfor = getAndRemoveAttr(el, 'v-for')
11+
delete el.attrsMap['v-for']
12+
if (process.env.NODE_ENV !== 'production' && vfor) {
13+
warn(
14+
`The v-for directive is not supported on a ${el.tag}, ` +
1615
'Use the "for" attribute instead. For example, instead of ' +
1716
`<${el.tag} v-for="${vfor}"> use <${el.tag} for="${vfor}">.`
18-
)
17+
)
18+
}
1919
}
2020

2121
const exp = getAndRemoveAttr(el, 'for') || vfor
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import class_ from './class'
22
import style from './style'
3-
import listView from './list-view'
3+
import for_ from './for'
44
import vTemplate from './v-template'
55
import view from './view'
66

7-
export default [class_, style, vTemplate, listView, view]
7+
export default [class_, style, vTemplate, for_, view]

samples/app/app-with-pager.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const Vue = require('./nativescript-vue')
2+
const Pager = require('nativescript-pager/vue')
3+
4+
Vue.use(Pager)
5+
6+
Vue.config.debug = true
7+
Vue.config.silent = false
8+
9+
new Vue({
10+
data() {
11+
return {
12+
selected: 2
13+
}
14+
},
15+
template: `
16+
<Page>
17+
<StackLayout>
18+
<Button text="go to first" @tap="selected = 0"/>
19+
<Button text="go to last" @tap="selected = 3"/>
20+
21+
<Pager for="i in [0,1,2,3]" v-model="selected" pagesCount="4">
22+
<v-template>
23+
<Label :text="i" backgroundColor="red" />
24+
</v-template>
25+
26+
<v-template if="i === 1">
27+
<Label :text="i" style="color: red;" backgroundColor="blue" />
28+
</v-template>
29+
30+
<v-template if="i === 2">
31+
<Label :text="i" style="color: blue;" backgroundColor="green" />
32+
</v-template>
33+
34+
<v-template if="i === 3">
35+
<Label :text="i" style="color: green;" backgroundColor="yellow" />
36+
</v-template>
37+
</Pager>
38+
</StackLayout>
39+
</Page>
40+
`
41+
}).$start()

samples/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
},
1515
"dependencies": {
1616
"nativescript-gradient": "^2.0.1",
17+
"nativescript-pager": "^7.1.0",
1718
"nativescript-pro-ui": "^3.3.0",
1819
"nativescript-theme-core": "^1.0.4",
1920
"tns-core-modules": "^3.4.0",

0 commit comments

Comments
 (0)