ember.js - How can I default a value of an Ember Model based on the result of an expression? -


the code below gives error saying: uncaught typeerror: undefined not function

can me structure can default value based on expression?

,defaultpersontype: function defaultpersontype() {         console.log(this)         var people = this.get("store").all("person").content             ,primaryfound = false             ,spousefound = false             ,dependantfound = false             ,defaulttype = "child"         (var = 0; < 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()     }()) 

well,

this 

is wrong in anonymous function. so, this:

function() { return this.defaultpersontype(); }.bind(this)()) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -