File tree Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,9 @@ Directive.prototype._bind = function () {
130
130
scope : this . _scope
131
131
}
132
132
)
133
- if ( this . _initValue != null ) {
133
+ if ( this . afterBind ) {
134
+ this . afterBind ( )
135
+ } else if ( this . _initValue != null ) {
134
136
watcher . set ( this . _initValue )
135
137
} else if ( this . update ) {
136
138
this . update ( watcher . value )
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ module.exports = {
23
23
}
24
24
}
25
25
26
- function getValue ( ) {
26
+ function getBooleanValue ( ) {
27
27
var val = el . checked
28
28
if ( val && el . hasOwnProperty ( '_trueValue' ) ) {
29
29
return el . _trueValue
@@ -40,16 +40,40 @@ module.exports = {
40
40
return val
41
41
}
42
42
43
- this . on ( 'change' , function ( ) {
44
- self . set ( getValue ( ) )
45
- } )
43
+ this . listener = function ( ) {
44
+ var model = self . _watcher . value
45
+ if ( _ . isArray ( model ) ) {
46
+ var val = getValue ( el )
47
+ if ( el . checked ) {
48
+ if ( _ . indexOf ( model , val ) < 0 ) {
49
+ model . push ( val )
50
+ }
51
+ } else {
52
+ model . $remove ( val )
53
+ }
54
+ } else {
55
+ self . set ( getBooleanValue ( ) )
56
+ }
57
+ }
58
+ this . on ( 'change' , this . listener )
46
59
47
60
if ( el . checked ) {
48
- this . _initValue = getValue ( )
61
+ this . afterBind = this . listener
49
62
}
50
63
} ,
51
64
52
65
update : function ( value ) {
53
- this . el . checked = this . _matchValue ( value )
66
+ var el = this . el
67
+ if ( _ . isArray ( value ) ) {
68
+ el . checked = _ . indexOf ( value , getValue ( el ) ) > - 1
69
+ } else {
70
+ el . checked = this . _matchValue ( value )
71
+ }
54
72
}
55
73
}
74
+
75
+ function getValue ( el ) {
76
+ return el . hasOwnProperty ( '_value' )
77
+ ? el . _value
78
+ : el . value
79
+ }
You can’t perform that action at this time.
0 commit comments