我习惯于在
Ember Object Model中计算属性.这是一种方便的方式来指定依赖于其他属性的计算属性.
@H_301_10@说fullName取决于firstName和lastName,我可以将计算属性设置为函数computeProperties,并在每次更改时调用computeProperties.
例:
function computeFullName(state) { const fullName = state.get('firstName') + state.get('lastName'); const nextState = state.set('fullName',fullName); return nextState; } function computeProperties(state) { const nextState = computeFullName(state); return nextState; } // store action handler [handleActionX](state) { let nextState = state.set('firstName','John'); nextState = state.set('lastName','Doe'); nextState = computeProperties(nextState); return nextState; }