如何在控制器复选框状态更改时重新加载模型?
How can I reload a model on controller checkbox state change?
给定一些 mut
布尔值的复选框,我们如何通过查询路由中的数据存储来使用这些布尔值自动更新模型?
例如:
model(params) {
return this.store.query('email', {
filter: {
option1: controller.checkbox1,
option2: controller.checkbox2,
option3: controller.checkbox3
}
})
}
您可以从 mut
移动到一个动作并使用 this.refresh()
{{input type="checkbox" checked=checkbox1 on-click=(action "refreshCheck")}}
{{input type="checkbox" checked=checkbox2 on-click=(action "refreshCheck")}}
{{input type="checkbox" checked=checkbox3 on-click=(action "refreshCheck")}}
actions: {
refreshCheck(){
this.refresh();
}
}
有两种既定模式:
- 使用 query parameters 存储 API 查询中使用的过滤器值。查询参数支持在开箱即用的更改时重新加载模型挂钩。
store.query()
解析的 DS.AdapterPopulatedRecordArray
提供了一个 update()
方法来重新加载查询。
在大多数情况下,我会推荐查询参数,因为它还允许共享和标记应用程序状态,包括过滤器。如果它只是关于布尔值,它不会增加很多复杂性。
您也可以 RouterService
to transition to the same route which works similar to refreshing the route. But it has some drawbacks as it adds more complexity compared to the other options and the default query parameters will be included in the route. See method documentation and the RouterService RFC 了解最后一个的更多详细信息。
给定一些 mut
布尔值的复选框,我们如何通过查询路由中的数据存储来使用这些布尔值自动更新模型?
例如:
model(params) {
return this.store.query('email', {
filter: {
option1: controller.checkbox1,
option2: controller.checkbox2,
option3: controller.checkbox3
}
})
}
您可以从 mut
移动到一个动作并使用 this.refresh()
{{input type="checkbox" checked=checkbox1 on-click=(action "refreshCheck")}}
{{input type="checkbox" checked=checkbox2 on-click=(action "refreshCheck")}}
{{input type="checkbox" checked=checkbox3 on-click=(action "refreshCheck")}}
actions: {
refreshCheck(){
this.refresh();
}
}
有两种既定模式:
- 使用 query parameters 存储 API 查询中使用的过滤器值。查询参数支持在开箱即用的更改时重新加载模型挂钩。
store.query()
解析的DS.AdapterPopulatedRecordArray
提供了一个update()
方法来重新加载查询。
在大多数情况下,我会推荐查询参数,因为它还允许共享和标记应用程序状态,包括过滤器。如果它只是关于布尔值,它不会增加很多复杂性。
您也可以 RouterService
to transition to the same route which works similar to refreshing the route. But it has some drawbacks as it adds more complexity compared to the other options and the default query parameters will be included in the route. See method documentation and the RouterService RFC 了解最后一个的更多详细信息。