javascript - TypeScript: Using function parameter as JSON-key name -
following situation:
setflags(data:any, key:string) { this.flags.key= data; }
assumed data {'foo': 'is cool'}
, key 'bar'
, flags should like:
{ 'bar': {'foo': 'is cool'} }
is there simple solution purpose?
edit: reply questions in comments: going typescriptclass used service, stores flags.
@injectable() export class formstoreservice { flags:any = {}; constructor() {} setflags(data:any, key:string) { this.flags.key = data; } }
when write foo.bar
, setting property named bar
. if name of property dynamic, should use foo[bar]
syntax. setflags
method becomes
setflags(data:any, key:string) { this.flags[key] = data; }
Comments
Post a Comment