I want to add filter in my array of object… I do not want duplicate check boxes with same same

后端 未结 1 1163
暖寄归人
暖寄归人 2021-01-26 02:32

My webpage :

Here you can see on left hand side I have set of checkboxes but also there are some repeated names which I

相关标签:
1条回答
  • 2021-01-26 03:15

    A better structure of your crop data according to your need would be :-

    crop.data.ts

    import { Crop } from "./crop.model";
    
    export const CROPS: Crop[] = [
        {
            name: "Rice",    // I want this Rice 
            checked: true,
            crops: [{
                district: "Thane",
                subCategory: [
                {
                    id: 1,
                    name: "Basmati",
                    checked: true
                },
                {
                    id: 2,
                    name: "Ammamore",
                    checked: true
                }]
             }, 
             {
                district: "Nashik",
                subCategory: [
                {
                    id: 1,
                    name: "Basmati",
                    checked: true
                },
                {
                    id: 2,
                    name: "Ammamore",
                    checked: true
                }]
             }
        },
        {
            name: "Wheat",
            checked: true,
            crops: [{
                district: "Nashik",
                subCategory: [
                    {
                        id: 1,
                        name: "Durum",
                        checked: true
                    },
                    {
                        id: 2,
                        name: "Emmer",
                        checked: true
                    }
                ]
            }]
        },
        {
            name: "Barley",
            checked: true,
            crops: [{
                district: "Ratnagiri",
                subCategory: [
                    {
                        id: 1,
                        name: "Hulless Barley",
                        checked: true
                    },
                    {
                        id: 2,
                        name: "Barley Flakes",
                        checked: true
                    }
                ]
            }]   
         }
     ];
    

    Also you can keep districts array instead of districts field if subcategories for a particular crops are always same. Else you can go for this approach which i have shown. And You UI can be modiefied according to crops data i have shared accordingly.

    0 讨论(0)
提交回复
热议问题