Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在object key angularjs中访问动态键值_Javascript_Angularjs - Fatal编程技术网

Javascript 如何在object key angularjs中访问动态键值

Javascript 如何在object key angularjs中访问动态键值,javascript,angularjs,Javascript,Angularjs,//这里我在字段变量中有first_name var value = attr.inlineEdit; var field = value.substring(11); 在字段键中,当我在字段变量中有first_name时,我希望它应该是have first_name,但我只得到字段作为键 这很奇怪,但我需要对它做点什么。为什么不创建嵌套对象,并将名字作为键: user.hit({field : scope.model}, auth.getCurrentUser().user_id).succ

//这里我在字段变量中有first_name

var value = attr.inlineEdit;
var field = value.substring(11);
在字段键中,当我在字段变量中有first_name时,我希望它应该是have first_name,但我只得到字段作为键


这很奇怪,但我需要对它做点什么。

为什么不创建嵌套对象,并将
名字作为键:

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

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

我认为{[field]:scope.model}是您真正想要的。这太棒了,非常感谢!
{field : { first_name : scope.model }}