获取动态范围变量值angularjs [英] Get dynamic scope variable value angularjs
问题描述
我有一个对象数组,其中包含多个范围变量名称.所有作用域变量值都已经设置过.
像这样的东西:
I have array of object which contains number of scope variable name in it. All the scope variable value has already been set before.
Something like this :
$scope.myarray = [{'id':'myname1'},{'id':'myname2'}];
$scope.myname1 = 'John';
$scope.myname2 = 'Rick';
现在,如果我想获取范围变量的值,该范围变量在"myarray"的"id"内,该怎么办?
我已经尝试过了
Now if I want to get value of the scope variable which within the 'id' of 'myarray',what should I do?
I have already tried this
var getMeMyValue = $scope[myarray[0]];
像这样的东西,但是没有帮助.
我在此示例中看到了如何动态设置作用域变量
但是我没有得到有关如何动态获得价值的任何信息
请帮助我,谢谢!
Something like this,but it didnt help.
I have seen in this example that how to set scope variable dynamically
But I didnt get anything about how to get value dynamically
Please help me with this,Thanks!!
P.S.在这里,我正在动态获取范围变量,因此无法直接访问它们以获取其值
P.S. Here I'm dynamically getting my scope variable so there is no way that I can access them directly to get their value
推荐答案
这将为您动态获得价值:
This will get the value for you dynamically:
var getMyValue = $scope[$scope.myarray[0].id];
这篇关于获取动态范围变量值angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!