获取动态范围变量值angularjs [英] Get dynamic scope variable value angularjs

查看:28
本文介绍了获取动态范围变量值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. Here I'm dynamically getting my scope variable so there is no way that I can access them directly to get their value

推荐答案

这将动态为您获取值:

var getMyValue = $scope[$scope.myarray[0].id];

这篇关于获取动态范围变量值angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆