0

I have an nested object array like this.

here is my array:

public collections: ICollections[] = [
  {
    collectionName: 'Brands',
    collectionFields: [
      {
        columnTitle : 'brandTitle',
        Type : dtEnum.string,
        control: {
          controlTitle: controlsEnum.input,
          controlType: controlsEnum.input,
          controlProperties: 
            {
              placeholder: 'Enter brand title here ...',
              type: 'text',
              autocomplete: false,
            }
        },
        columnWidth: 200
      }
    ],
    collectionFieldValidation: [{name: 'test'}],
    hasPaginator: true,
    stickyColumn: 0,
    stickyHeader: true
  },
    {
      columnTitle : 'brandURL',
      Type : dtEnum.string,
      control: {
        controlTitle: controlsEnum.input,
        controlType: controlsEnum.input,
        controlProperties: {
          placeHolder: 'Enter Brand URL',
          type: 'text',
          autocomplete: false,
        }
      },
      columnWidth: 300
    },
    {
      columnTitle : 'brandDescription',
      Type : dtEnum.string,
      control: {
        controlTitle: controlsEnum.textarea,
        controlType: controlsEnum.textarea,
        controlProperties: {
          placeHolder: 'Enter Brand Description',
          type: 'text',
          autocomplete: false,
        }
      },
      columnWidth: 300
    }
];

I want to reach to placeholder field. how do I find it by having only collectionName field with Brands value and columnTitle field with brandURL value ?

this question asked before just with collectionName field value but I find out that my filter should include more than one field.

2
  • 1
    Check this:stackblitz.com/edit/angular-wrbfrf Commented Jul 7, 2019 at 6:55
  • @PrashantPimpale Hi bro, I added some extra information to my question. would you please take a look again? Commented Jul 7, 2019 at 20:46

2 Answers 2

1

first of all, find the collection that corresponds to "Brands" or any other thing:

let result = collections.find(p => p.collectionName === "Brands");

then get the placeholder field:

change your_index to 0 or your specific index

if (result) {
    let placeholder = result.collectionFields[your_index].control.controlProperties.placeholder;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Here is my solution :

  placeholder_finder(collectionSearchKey: string, fieldSearchKey: string): string {
    let field: any;
    let placeholder: string;
    const obj = this.genInfo.collections.filter(
      x => x.collectionName === collectionSearchKey
    );
    obj.forEach(data => {
      field = data.collectionFields.filter(
        x => x.columnTitle === fieldSearchKey
      );
    });
    field.forEach(element => {
      placeholder = element.control.controlProperties.placeHolder;
    });
    return placeholder;
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.