Ember版本1.9.1
执行this.get('wallet.bank_account_format')
我得到undefined
。
做this.get('wallet')
我得到
{
__ember_meta__: Object { descs: {…}, watching: {…}, cache: {}, … }
…
bank_account_format: "bban-se"
…
__proto__: Object { … }
}
但最令人困惑的部分是,如果我尝试使用开发工具this.get('wallet.bank_account_format')
,我会正确地获得"bban-se"
。
我做错了什么?
以下是我正在进行this.get
的完整模型:
App.Influencer = App.User.extend({
role : 'member',
services : [],
interests : [],
persistent : [
'about',
'activated',
'birthdate',
'client_id',
'country',
'email',
'gender',
'language',
'mobile',
'name',
'network_id',
'role',
'slug',
'wallet'
],
/*
|-----------------------------------------------------------
| PROPERTIES
|-----------------------------------------------------------
*/
birthdate : function(key, value) {
if (value) {
var birthdate = value.split('-');
this.set('year', birthdate[0]);
this.set('month', birthdate[1]);
this.set('day', birthdate[2]);
}
return this.get('year') ? this.get('year') + '-' + this.get('month') + '-' + this.get('day') : null;
}.property('day', 'month', 'year'),
service : function() {
var followers = {},
services = this.get('services');
App.Resources.get('services').forEach(function(service) {
var userService = services.findBy('service.identifier', service.service);
var engagement = userService ? userService.reach.findBy('identifier', service.service + '-engagement') : null;
var serviceFollowers = userService ? userService.reach.findBy('identifier', 'followers') : null;
var views = userService ? userService.reach.findBy('identifier', 'views') : null;
followers[service.service] = {
'followers' : userService ? userService.followers : 0,
'disconnected' : userService ? !userService.connected : false,
'crawler' : userService ? (userService.hasOwnProperty('crawler') && userService.crawler === true) : false,
'engagement' : engagement ? engagement.value : 0,
'views' : views ? views.value : 0,
'percent' : serviceFollowers ? serviceFollowers.percent : 0
}
});
return followers;
}.property('services.@each.followers'),
instagram : function() {
var instagram = this.get('services').findBy('service', 'instagram');
if (instagram)
return instagram.username;
}.property('services.@each.username'),
url : function() {
return 'http://my.gosnap.co/' + this.get('slug');
}.property('slug'),
wallet : function(key, value) {
return Ember.isEmpty(value) ? {is_company: false} : value;
}.property(),
allInterests : function() {
var interests = this.get('interests'),
allInterests = Ember.copy(App.Resources.get('interests'));
return allInterests.map(function(interest) {
interest.set('isChecked', (interests && interests.contains(interest.slug)));
return interest;
});
}.property('App.Resources.interests.length', 'interests'),
selectedInterests : Ember.computed.filterBy('allInterests', 'isChecked', true),
/*
|-----------------------------------------------------------
| WALLET
|-----------------------------------------------------------
*/
hasManyAccountFormats : Ember.computed.gt('accountFormats.length', 1),
isPrivate : function() {
return !!this.get('wallet.is_company');
}.property('wallet.is_company'),
hasMultiFieldAccount : function() {
var format = this.get('accountFormat.type');
return (format && format.indexOf('bban') > -1) || format === 'biciban';
}.property('accountFormat.type'),
ssnDescription : function() {
var key = 'description.ssn.' + this.get('wallet.country').toLowerCase();
var desc = Translation.get(key);
return desc !== key ? desc : null;
}.property('wallet.country'),
accountFormatLabel : function() {
return {
first : Translation.get('field.' + this.get('accountFormat.translationType') + '.first'),
second : Translation.get('field.' + this.get('accountFormat.translationType') + '.second')
};
}.property('accountFormat.translationType'),
accountFormatDescription : function() {
return {
first : Translation.get('description.' + this.get('accountFormat.translationType') + '.first'),
second : Translation.get('description.' + this.get('accountFormat.translationType') + '.second')
};
}.property('accountFormat.translationType'),
companyNumberDescription : function() {
var key = 'description.company.number.' + this.get('wallet.country').toLowerCase();
var desc = Translation.get(key);
return desc !== key ? desc : null;
}.property('wallet.country'),
taxDescription : function() {
return Translation.get('description.tax');
}.property(),
accountFormat : function() {
return this.get('accountFormats').findBy('type', this.get('wallet.bank_account_format'));
}.property('accountFormats'),
accountFormats : function() {
var countries = App.Resources.get('walletCountries');
var isPrivate = this.get('isPrivate');
if (!countries || countries.length === 0)
return [];
var country = countries.findBy('code', this.get('wallet.country'));
if (country && country.account_number_types) {
var formats = country.account_number_types
.filter(function(type) {
return type !== 'bban' && (type !== 'iban' && (type !== 'pg' && type !== 'bg' || isPrivate));
})
.map(function(type) {
var translationType = type;
if (translationType.indexOf('bban') !== -1) {
translationType = 'bban';
}
return {
type : type,
translationType : translationType,
label : Translation.get('field.' + translationType),
description : Translation.get('description.' + translationType)
};
});
var type = formats.findBy('type', this.get('wallet.bank_account_format'));
if (type) {
this.set('accountFormat', type);
} else {
this.set('accountFormat', formats.get('firstObject'));
}
return formats;
}
return [];
}.property('isPrivate', 'wallet.country', 'App.Resources.walletCountries.length'),
isTaxField : function() {
return this.get('wallet.country') == 'NO' || this.get('wallet.country') == 'FI';
}.property('wallet.country'),
/*
|-----------------------------------------------------------
| OBSERVERS
|-----------------------------------------------------------
*/
updateWalletBankAccountFormat : function() {
this.set('wallet.bank_account_format', this.get('accountFormat.type'));
}.observes('accountFormat'),
/*
|-----------------------------------------------------------
| METHODS
|-----------------------------------------------------------
*/
beforeSave: function(data) {
data.interests = this.get('selectedInterests').map(function(item) {
return item ? item.slug : null;
});
return data;
}
});