Skip to content

Commit

Permalink
checkbox 也尝试进行类型转换
Browse files Browse the repository at this point in the history
  • Loading branch information
RubyLouvre committed Oct 13, 2014
1 parent 6749c23 commit adf5d4c
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 153 deletions.
19 changes: 15 additions & 4 deletions avalon.js
Expand Up @@ -3236,7 +3236,7 @@
//当model变化时,它就会改变value的值
data.handler = function() {
var val = evaluator()
val = val == null ? "" : val
val = val == null ? "" : val
setTypeValue(data, val)
val += ""
if (val !== element.value) {
Expand Down Expand Up @@ -3290,13 +3290,24 @@
if (!Array.isArray(array)) {
array = [array]
}
avalon.Array[method](array, element.value)
avalon.Array[method](array, getTypeValue(data,element.value))
callback.call(element, array)
}
}
data.handler = function() {
var array = [].concat(evaluator()) //强制转换为数组
element.checked = array.indexOf(element.value) >= 0
var types = array.map(function(val) {
var type = typeof val
return type === "number" || type === "boolean" ? type : "string"
})
var maybeType = types[0]
if(types.some(function(type){
return type !== maybeType
})){
maybeType = "string"
}
data.msType = maybeType
element.checked = array.indexOf(getTypeValue(data,element.value)) >= 0
}

bound(W3C ? "change" : "click", updateVModel)
Expand Down Expand Up @@ -3357,7 +3368,7 @@
function getTypeValue(data, val) {
switch (data.msType) {
case "boolean":
return val == "true"
return val === "true"
case "number":
return isFinite(val) ? Number(val) : val
default:
Expand Down

0 comments on commit adf5d4c

Please sign in to comment.