迭代angularjs中另一个服务中的函数返回的数组
我的控制器中有一个函数,它正在调用该控制器共享的服务中定义的函数。我能够正确地进行调用,但该函数返回一个数组,我希望从该数组中获取单个项。下面是片段迭代angularjs中另一个服务中的函数返回的数组,angularjs,arrays,iteration,Angularjs,Arrays,Iteration,我的控制器中有一个函数,它正在调用该控制器共享的服务中定义的函数。我能够正确地进行调用,但该函数返回一个数组,我希望从该数组中获取单个项。下面是片段 ctrl.loadInterfaces = function(driver) { angular.forEach(ctrl.driverInterfaces, function(value, key){ ctrl.interfaces = myservice.driverInfo(driver, value);
ctrl.loadInterfaces = function(driver) {
angular.forEach(ctrl.driverInterfaces, function(value, key){
ctrl.interfaces = myservice.driverInfo(driver, value);
})
};
在这里,driverInfo()将返回一个数组,类似于['one','two',],但现在我想将其拆分,并分别将'one'和'two'放入ctrl.interfaces中,而不是像数组一样。你知道我该怎么做吗?
顺便说一下,ctrl.DriverInterface只是控制器中声明的另一个静态数组
我的html
<select>
<option ng-repeat="interface in ctrl.interfaces"
value="{$ interface }">{$ interface $}</option>
</select>
{$interface$}
我们非常感谢您的投入。谢谢你试试这个
ctrl.loadInterfaces = function(driver) {
ctrl.interfaces = [];
angular.forEach(ctrl.driverInterfaces, function(value, key){
ctrl.interfaces = ctrl.interfaces.concat(myservice.driverInfo(driver, value));
})
};
ctrl.interfaces
是什么样的数据结构?这是一个数组吗?嗨,CodeWarrior,我现在已经将其定义为ctrl.interfaces=null。因此,现在只需要一个对象,您希望迭代myservice.driverInfo()返回的数组。。您希望如何填充ctrl.interfaces
。你有这样的模式吗,第一个元素应该转到ctrl.interfaces.name
,第二个元素应该转到ctrl.interfaces.id
,等等?我可以更改ctrl.interfaces=[],如果这会使我想要实现的目标变得容易的话。那么我能在ng中使用ctrl.interfaces来重复ctrl.interfaces中的interfaces吗?并使用{$interface$}中的值?interface中的属性是什么?我只是想找出其中的属性,你想成为显示文本,以及你想成为值的属性。你可以用正确的属性名替换.value
和.description
,{{interface.description}}
我们可以打开一个聊天室,在那里解释我的事情吗?嘿,聊天室里没看到你吗?请粘贴链接好吗