你在那里的东西似乎是正确的。也许错误在于mut
用法,也许它在其他地方。
mut
助手很模糊。当 Ember 团队弄清楚如何优雅地做到这一点时,它将被弃用。
mut
您可以通过在控制器/组件上创建不同的操作来避免使用帮助程序。
这将让您调试:只需debugger
在您的操作中添加一条语句并从那里继续。
经典的 Ember 风格:
import Component from '@ember/component';
export default Component.extend({
timeZoneOptions: Object.freeze([
{ groupName: "Asia", options:["Kabul","Yerevan","Baku","Dhaka","Brunei","Bangkok","Shanghai","Urumqi","Taipei","Macau","Tbilisi","Dili","Kolkata","Jakarta"]},
{ groupName: "Australia", options: ["Darwin", "Eucla", "Perth", "Brisbane","Lindeman","Adelaide","Hobbart","Currie","Melbourne"]},
]),
currentTimeZoneOption: null,
actions: {
selectTimeZoneOption(timeZoneOption) {
this.set('currentTimeZoneOption', timeZoneOption');
}
}
});
{{#paper-select
options=this.timeZoneOptions
selected=this.currentTimeZoneOption
onChange=(action 'selectTimeZoneOption')
as |timeZoneOption|
}}
{{timeZoneOption}}
{{/paper-select}}
<p>
Current timezone option:
{{this.currentTimeZoneOption.groupName}}
</p>
Ember Octane 风格:
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class MyComponent extends Component {
timeZoneOptions = Object.freeze([
{ groupName: "Asia", options:["Kabul","Yerevan","Baku","Dhaka","Brunei","Bangkok","Shanghai","Urumqi","Taipei","Macau","Tbilisi","Dili","Kolkata","Jakarta"]},
{ groupName: "Australia", options: ["Darwin", "Eucla", "Perth", "Brisbane","Lindeman","Adelaide","Hobbart","Currie","Melbourne"]},
]);
@tracked
currentTimeZoneOption = null;
@action
selectTimeZoneOption(timeZoneOption) {
this.currentTimeZoneOption = timeZoneOption;
}
}
<div class="my-component">
<PaperSelect
@options={{this.timeZoneOptions}}
@selected={{this.currentTimeZoneOption}}
@onChange={{this.selectTimeZoneOption}}
as |timeZoneOption|
>
{{timeZoneOption}}
</PaperSelect>
<p>
Current timezone option:
{{this.currentTimeZoneOption.groupName}}
</p>
</div>