Skip to content

Commit 67a376c

Browse files
committed
Merge pull request vuejs#718 from calebboyd/dev
fix vuejs#712: allow filters on options expression of v-model
2 parents 67759d2 + 3ced676 commit 67a376c

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/directives/model/select.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var _ = require('../../util')
22
var Watcher = require('../../watcher')
3+
var dirParser = require('../../parsers/directive')
34

45
module.exports = {
56

@@ -61,6 +62,7 @@ module.exports = {
6162

6263
function initOptions (expression) {
6364
var self = this
65+
var descriptor = dirParser.parse(expression)[0]
6466
function optionUpdateWatcher (value) {
6567
if (_.isArray(value)) {
6668
self.el.innerHTML = ''
@@ -74,9 +76,12 @@ function initOptions (expression) {
7476
}
7577
this.optionWatcher = new Watcher(
7678
this.vm,
77-
expression,
79+
descriptor.expression,
7880
optionUpdateWatcher,
79-
{ deep: true }
81+
{
82+
deep: true,
83+
filters: _.resolveFilters(this.vm, descriptor.filters)
84+
}
8085
)
8186
// update with initial value
8287
optionUpdateWatcher(this.optionWatcher.value)

test/unit/specs/directives/model_spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,27 @@ if (_.inBrowser) {
313313
expect(vm.test).toBe(1)
314314
})
315315

316+
it('select + options + filter', function () {
317+
var vm = new Vue({
318+
el: el,
319+
data: {
320+
opts: ['a','b']
321+
},
322+
filters: {
323+
aFilter: function (opts){
324+
return opts.map(function (val,i){
325+
return val + i
326+
})
327+
}
328+
},
329+
template: '<select v-model="test" options="opts | aFilter"></select>'
330+
})
331+
expect(el.firstChild.innerHTML).toBe(
332+
'<option value="a0">a0</option>' +
333+
'<option value="b1">b1</option>'
334+
)
335+
})
336+
316337
it('text', function (done) {
317338
var vm = new Vue({
318339
el: el,

0 commit comments

Comments
 (0)