使用当前作用域中的对象从ng中调用函数repeat



我正试图从ng repeat调用一个函数(来自非事件元素),以将数据数组馈送到自动完成元素(使用https://github.com/JustGoscha/allmighty-autocomplete)。

这是为了生成一种逻辑系统:

type(listbox) | comparator (eg:>=) (listbox) | value(autocomplete)

其中的几个对象可以在网页上列出,以获得一些复杂的逻辑

type=value && type2>value3 || ...

根据类型和比较器的不同,值会有所不同。

迄今为止的代码(简化):

<div class="comparator" ng-repeat="comp in container.comparators">
    <select ng-model="comp.type"><option ng-repeat="i in type_options" value="{{i.value}}" ng-selected="{{i.value==comp.type}}">{{i.label}}</option></select>
    <select ng-model="comp.comparator"><option ng-repeat="i in comp_options|filter:typeMatch(comp)" value="{{i.value}}" ng-selected="{{i.value==comp.comparator}}">{{i.label}}</option></select>
    <autocomplete class="autocomplete" data="" attr-placeholder="Entrez votre valeur" click-activation="true" on-type="**updateValue**" ng-model="comp.value"></autocomplete>
</div>

updateValue是要调用的函数,但我需要知道当前对象(来自ng repeat的comp),以便在其上发送正确的值数组。

我尝试发送一个现有数组以避免"摘要循环"$scope.updateValue=函数(crit){对于(var i=0;i

我还试着做一个函数,返回一个返回数组的函数:DDDDD:

    $scope.updateValue = function(crit){
        return function(value/*not used*/){
        for(var i=0;i<$scope.comp_options.length;i++) {
            if($scope.comp_options[i].value===crit.comparator){
                $scope.value_elements=$scope.comp_options[i].info;
                break;
            }
        }
        return $scope.value_elements;
        };
    };

将自动完成对象替换为:

如果我console.log(comp),我看到我可以得到我的对象,但我得到了一个摘要循环。。。

有没有办法知道我被呼叫的"线路"的对象?

Thx(我是一个角度方面的新手,但到目前为止,我一直找不到如何检索这些信息……这可能吗:)。

使用$index访问它?以下示例。然后您可以使用索引来访问它

<tr ng-repeat="user in uc.users track by $index">
            <td>{{user.id}}</td>
            <td>{{user.first_name}}</td>
            <td>{{user.last_name}}</td>
            <td>{{user.email}}</td>
            <td>{{user.department}}</td>
            <button ng-click="uc.open(user.id, $index);">Open</button>
</tr>

最新更新