https:/github.comrokudo5262phone。 这是我的项目,我想在智能表格中加载品牌列表,但得到的警告,我试图修复,但警告仍然存在,请帮助品牌-特征.选择器.ts。
import { createFeatureSelector } from '@ngrx/store';
import { State, FeatureKey } from '../reducers';
export const selectBrandsState = createFeatureSelector<State>(FeatureKey);
品牌选择器.ts
import { createSelector } from '@ngrx/store';
import { selectBrandsState } from './brands-features.selector';
import { BrandsReducer } from '../reducers';
import { brandAdapter } from '../states/brands.state';
export const selectBrandEntitiesState = createSelector(
selectBrandsState,
state => state[BrandsReducer.brandsFeatureKey],
);
export const {
selectIds: selectBrandIds,
selectEntities: selectBrandEntities,
selectAll: selectAllBrands,
selectTotal: selectTotalBrands,
} = brandAdapter.getSelectors(selectBrandEntitiesState);
export const BrandSelectors = {
selectBrandEntitiesState,
selectBrandIds,
selectBrandEntities,
selectAllBrands,
selectTotalBrands,
};
export const selectCurrentBrand = (brand_id) => createSelector(
selectBrandEntities,
(brand) => brand[brand_id],
)
品牌.选择器.索引.ts
export * from './brands-features.selector';
import * as BrandsSelector from './brands.selector';
export {
BrandsSelector,
};
Brand.reducer.ts
import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
import { IBrand } from '../../../@core/data/brands';
export interface BrandsState extends EntityState<IBrand> {
selectedBrandID: number | string | null;
}
export const brandAdapter: EntityAdapter<IBrand> = createEntityAdapter<IBrand>({
selectId: (brand: IBrand) => brand.brand_id,
sortComparer: null,
});
export const brandInitialState: BrandsState = brandAdapter.getInitialState({
selectedBrandID: null,
entities: {
0: {},
},
});
我想问题出在 selectCurrentBrand
你可以分享一下你是如何使用它的吗?
export const selectCurrentBrand = (brand_id) => createSelector(
selectBrandEntities,
(brand) => brand[brand_id],
)
如果你这样做 this.store.select(selectCurrentBrand, 123)
那么,正确的方法是
export const selectCurrentBrand = createSelector(
selectBrandEntities,
(brand, brand_id) => brand[brand_id],
)
选择器
this.roomgroup$ = this.store.pipe(select(RoomGroupSelectors.selectCurrentRoomGroup, this.id$))
我发现了问题,原来问题出在我的"''brand_id''"中。Brand Table
, entity.Property(e => e.BrandId).HasColumnName("brand_id");
和 brand_id
在我 Ibrand interface
所以我把所有的东西都改成了 brandCode
而警告已经消失了。
modelBuilder.Entity<Brands>(entity =>
{
entity.HasKey(e => e.BrandCode)
entity.Property(e => e.BrandCode).HasColumnName("brandCode");
entity.Property(e => e.BrandName)
.HasColumnName("brandName")
.HasMaxLength(255);
entity.Property(e => e.CreatedBy)
.HasColumnName("createdBy")
.HasMaxLength(255);
entity.Property(e => e.CreatedDateTime)
.HasColumnName("createdDateTime")
.HasColumnType("datetime");
entity.Property(e => e.Deleted).HasColumnName("deleted");
entity.Property(e => e.Remark)
.HasColumnName("remark")
.HasMaxLength(255);
entity.Property(e => e.Status)
.HasColumnName("status")
.HasMaxLength(255);
entity.Property(e => e.UpdatedDateTime)
.HasColumnName("updatedDateTime")
.HasColumnType("datetime");
entity.Property(e => e.Updatedby)
.HasColumnName("updatedby")
.HasMaxLength(255);
});
export const brandAdapter: EntityAdapter<IBrand> = createEntityAdapter<IBrand>({
selectId: (brand: IBrand) => brand.brandCode,
sortComparer: null,
});
export interface IBrand {
brandCode: number;
brandName: string;
status: string;
remark: string;
deleted: boolean;
createdBy?: string;
createdDateTime?: Date;
lastUpdatedBy?: string;
lastUpdatedDateTime?: Date;
}