下面的代码给出了一个错误:未捕获的TypeError:未定义的不是一个函数
有没有人能帮我把它合理地组织起来,这样我就可以根据这个表达式默认一个值?
,defaultPersonType: function defaultPersonType() {
console.log(this)
var people = this.get("store").all("person").content
,primaryFound = false
,spouseFound = false
,dependantFound = false
,defaultType = "CHILD"
for (var i = 0; i < people.length; i++) {
switch(people.get("personType")) {
case "PRIMARY":
primaryFound = true
break
case "SPOUSE":
spouseFound = true
break
case "UNMARRIED_PARTNER":
spouseFound = true
break
default:
dependantFound = true
break
}
if (!primaryFound) {
defaultType = "PRIMARY"
}
if (!!dependantFound) {
defaultType = "CHILD"
}
if (!spouseFound) {
defaultType = "SPOUSE"
}
}
return DS.attr('string', {defaultValue: function() {return defaultType}})
}
,personType: (function() {
return this.defaultPersonType()
}())
发布于 2014-04-12 14:44:26
嗯,你的
this
匿名函数中的错误。因此,执行以下操作:
function() { return this.defaultPersonType(); }.bind(this)())
https://stackoverflow.com/questions/23023715
复制相似问题