简体   繁体   中英

How to access dynamic key value in object key angularjs

var value = attr.inlineEdit;
var field = value.substring(11);

//Here I have first_name in field variable

user.hit({field : scope.model}, auth.getCurrentUser().user_id).success(function () {
     console.log("Saved");
});

In the field key, I want that should be have first_name when I have first_name in field variable but I'm getting only field as a key.

It's weird but I need to do something on it.

我认为{[field]:scope.model}是您真正想要的。

为什么不使用first_name作为键来创建嵌套对象:

{field : { first_name : scope.model }}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM