这是用于将 json 对象解析和绑定为属性(也有一个转换,但它非常基本):
cleanCredentials: ->
creds = @get('credentials')
Object.keys(creds).forEach (key) =>
unless key in @get('selectedDriver').api_keys
delete @get('credentials')["#{key}"]
get_set: ->
key = arguments[0][0]
value = arguments[0][1]
if (arguments[0].length > 1)
@set "credentials.#{key}", value
@cleanCredentials()
@get "credentials.#{key}"
getter_setter = `function(key, value) { return this.get_set(arguments); }.property('credentials')`
apiToken: getter_setter
applicationId: getter_setter
applicationUserId: getter_setter
companyCode: getter_setter
username: getter_setter
它有效,我理解,但有更好的方法吗?