Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import { Base } from '../_base';
  2.  
  3. export interface ICarOptionBackend {
  4. id: number;
  5. carId: number;
  6. }
  7.  
  8. export class CarOption extends Base {
  9. public id: number = null;
  10. public name: number = null;
  11. public parentId: number = null;
  12. public checked = false;
  13.  
  14. protected mapping: Array<Object> = [
  15. { key: 'id', value: 'id' },
  16. { key: 'name', value: 'name' },
  17. { key: 'parentId', value: 'parent_id' },
  18. ];
  19.  
  20. static setChecked(opts: CarOption[],
  21. options: CarOption[]): CarOption[] {
  22. let optsIds: number[] = options.map(item => item.id);
  23.  
  24. return opts.map((item: CarOption) => {
  25. item.checked = optsIds.indexOf(item.id) > -1;
  26. return item;
  27. });
  28. }
  29.  
  30. constructor(carOption?: ICarOptionBackend) {
  31. super();
  32.  
  33. if (carOption) {
  34. this.deserialize(carOption);
  35. }
  36. }
  37.  
  38. public clone(): CarOption {
  39. let carOption: CarOption = new CarOption();
  40. Object.assign(carOption, this);
  41. return carOption;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement