I want to include a variable in the property names

Asked 2 years ago, Updated 2 years ago, 140 views

I want to put a variable in the property name, but I get an error.
The code is as follows.
Is there any good way?
Thank you for your cooperation.

var overrideCtx={};
    overrideCtx.Templates={};

    for(vari=1;i<=127;i++){
        var hoge="";
        hoge+="Test";
        hoge+=i

        overrideCtx.Templates.Fields={
           hoge: {'DisplayForm': ConvertIcon}
        };

javascript sharepoint

2022-09-30 21:22

1 Answers

Use Property Name to access object properties.

var overrideCtx={};
overrideCtx.Templates={};
overrideCtx.Templates.Fields={};
for(vari=1;i<=127;i++){
    var hoge="";
    hoge+="Test";
    hoge+=i

    overrideCtx.Templates.Fields [hoge] = {value:hoge};
}


2022-09-30 21:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.