在 Ember.js Octane 中使用多个属性查找
Find-by with multiple attribute in Ember.js Octane
我有一条带有 RSVP 的路线,它加载了 return JsON API 格式的几个模型(包含项目、治疗、价格的类别),并希望在 API 中显示它们=40=]:
Item Name
Treatment Name 1
Treatment Name N
Category 1
Item 1 in Cat 1
Price item 1 in Cat 1 for Treatment 1
Setup Price
Item 2 in Cat 1
Setup Price
Price item 2 in Cat 1 for Treatment N
Category 2
Item 1 in Cat 2
Price item 1 in Cat 2 for Treatment 1
Price item 1 in Cat 2 for Treatment N
Setup Price
仅在未找到任何价格时显示,因此用户可以为该处理中的商品设置价格
我已经可以迭代类别、项目和治疗;但还是不知道如何配置才能显示正确的价格。
如何通过 2 个属性找到正确的价格?我尝试在模板中使用 find-by
助手:
{{#let (find-by "item.id" item.id @model.prices) as |price|}}
{{price.amount}}
{{/let}}
,不过好像只支持1个属性。
嗯,如果在 SQL 中,它会是这样的:
select * from prices where item.id = [currentItemId] and treatment.id = [currentTreatmentId]
但我希望它在已加载的价格模型中搜索...
有什么帮助吗?谢谢...
如果您正在使用 find-by from ember-composable-helpers it looks like you have the correct syntax. You may need to update this addon if it is installed or else investigate where find-by
is coming from in your app as it isn't a default ember helpers. You can also solve this with a helper。调用为:
{{#let (find-price-for-item item @model.prices) as |price|}}
{{price.amount}}
{{/let}}
可能看起来像:
// app/helpers/find-price-for-item.js
import { helper } from '@ember/component/helper';
function findPriceForItem([item, prices]) {
return prices.find(price => price.item.id === item.id);
}
export default helper(findPriceForItem);
我有一条带有 RSVP 的路线,它加载了 return JsON API 格式的几个模型(包含项目、治疗、价格的类别),并希望在 API 中显示它们=40=]:
Item Name | Treatment Name 1 | Treatment Name N |
---|---|---|
Category 1 | ||
Item 1 in Cat 1 | Price item 1 in Cat 1 for Treatment 1 | Setup Price |
Item 2 in Cat 1 | Setup Price | Price item 2 in Cat 1 for Treatment N |
Category 2 | ||
Item 1 in Cat 2 | Price item 1 in Cat 2 for Treatment 1 | Price item 1 in Cat 2 for Treatment N |
Setup Price
仅在未找到任何价格时显示,因此用户可以为该处理中的商品设置价格
我已经可以迭代类别、项目和治疗;但还是不知道如何配置才能显示正确的价格。
如何通过 2 个属性找到正确的价格?我尝试在模板中使用 find-by
助手:
{{#let (find-by "item.id" item.id @model.prices) as |price|}}
{{price.amount}}
{{/let}}
,不过好像只支持1个属性。
嗯,如果在 SQL 中,它会是这样的:
select * from prices where item.id = [currentItemId] and treatment.id = [currentTreatmentId]
但我希望它在已加载的价格模型中搜索...
有什么帮助吗?谢谢...
如果您正在使用 find-by from ember-composable-helpers it looks like you have the correct syntax. You may need to update this addon if it is installed or else investigate where find-by
is coming from in your app as it isn't a default ember helpers. You can also solve this with a helper。调用为:
{{#let (find-price-for-item item @model.prices) as |price|}}
{{price.amount}}
{{/let}}
可能看起来像:
// app/helpers/find-price-for-item.js
import { helper } from '@ember/component/helper';
function findPriceForItem([item, prices]) {
return prices.find(price => price.item.id === item.id);
}
export default helper(findPriceForItem);