[英]NGRX Entity - how to handle isSelected property properly?
I have a table where each row might be clicked and then it should change a color and later on be used to filter out selected items.我有一个表格,可以单击每一行,然后它应该更改颜色,然后用于过滤掉选定的项目。 In each row I have an item:在每一行我都有一个项目:
interface Item{
id:string;
name:string;
price:number;
}
I am wondering what is a better approach regarding EntityStateAdapter:我想知道关于 EntityStateAdapter 的更好方法是什么:
isSelected
property to Item
and later on updating this part of state?将isSelected
属性添加到Item
以及稍后更新 state 的这一部分?OR或者
export const adapter: EntityAdapter<Item> = createEntityAdapter<Item>();
export const initialState: EntityState<Item> = adapter.getInitialState({
selectedItems:Array<string>
})
IMO 1st approach is better. IMO 第一种方法更好。 It is easier to just add property to Item, because later on I can easily reflect the state in table for each row just by item.isSelected
.将属性添加到 Item 更容易,因为稍后我可以通过 item.isSelected 轻松地在表中为每一行反映item.isSelected
。 I would like to hear about your experience.我想听听你的经历。
I prefer to use selectedItems
, reasons:我更喜欢使用selectedItems
,原因:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.