Angularjs ng类-在对象内查找值

Angularjs ng类-在对象内查找值,angularjs,javascript-objects,ng-class,Angularjs,Javascript Objects,Ng Class,我有一个像这样的对象: $scope.things = [ { name: 'Bob!', short_name: 'bob', info: 'something something' }, { name: 'Steve', short_name: 'steve', info: 'something something something' }, ]; 我像这样循环浏

我有一个像这样的对象:

$scope.things = [
    {
        name: 'Bob!',
        short_name: 'bob',
        info: 'something something'
    },
    {
        name: 'Steve',
        short_name: 'steve',
        info: 'something something something'
    },
];
我像这样循环浏览它们,并添加一个ng单击:

<div ng-repeat="thing in things" ng-click="addThing(thing.name, thing.short_name, thing_info" ng-class="thingClass(thing.name)">content goes here</div>
…物体现在的样子。我尝试从这里改编一些通过谷歌找到的答案,例如:

$scope.teamClass = function(name) {

    var found = $filter('filter')($scope.thingSelected, {id: name}, true);

    if (found.length) {
        return 'selected';
    }

};  
…但毫无乐趣


有人能指出/推动我正确的方向吗?

您只需将thing对象传递给
thingClass

... ng-class="thingClass(thing)" ...
并实现
thingClass
,如下所示:

$scope.thingClass= function(thing) {
    return $scope.thingSelected.indexOf(thing) >= 0 ? 'selected' : '';
}
也许你也应该把这项技术应用到
addThing
上:

... ng-click="addThing(thing)" ...

$scope.addThing = function(thing) {
    if ($scope.thingSelected.indexOf(thing) < 0)
        $scope.thingSelected.push(thing);
}

您只需将thing对象传递给
thingClass

... ng-class="thingClass(thing)" ...
并实现
thingClass
,如下所示:

$scope.thingClass= function(thing) {
    return $scope.thingSelected.indexOf(thing) >= 0 ? 'selected' : '';
}
也许你也应该把这项技术应用到
addThing
上:

... ng-click="addThing(thing)" ...

$scope.addThing = function(thing) {
    if ($scope.thingSelected.indexOf(thing) < 0)
        $scope.thingSelected.push(thing);
}

您只需将thing对象传递给
thingClass

... ng-class="thingClass(thing)" ...
并实现
thingClass
,如下所示:

$scope.thingClass= function(thing) {
    return $scope.thingSelected.indexOf(thing) >= 0 ? 'selected' : '';
}
也许你也应该把这项技术应用到
addThing
上:

... ng-click="addThing(thing)" ...

$scope.addThing = function(thing) {
    if ($scope.thingSelected.indexOf(thing) < 0)
        $scope.thingSelected.push(thing);
}

您只需将thing对象传递给
thingClass

... ng-class="thingClass(thing)" ...
并实现
thingClass
,如下所示:

$scope.thingClass= function(thing) {
    return $scope.thingSelected.indexOf(thing) >= 0 ? 'selected' : '';
}
也许你也应该把这项技术应用到
addThing
上:

... ng-click="addThing(thing)" ...

$scope.addThing = function(thing) {
    if ($scope.thingSelected.indexOf(thing) < 0)
        $scope.thingSelected.push(thing);
}


$scope.thingSelected
$scope.thingSelected
中的一个对象吗?在这里键入
ng click=“addThing(thing.name,thing.short\u name,thing.info)”
什么是
$scope.thingSelected
??这是一个包含每个添加对象的对象数组,还是一个数组?请给出一个plunker。函数调用中的输入错误和添加类没有正确完成Wero,是的-这里不是100%清楚,但我使用$scope.things创建一个项目列表(使用ng repeat),如果单击一个项目,它既被添加到$scope.thingSelected中,也应该通过添加classIs
$scope.thingSelected
$scope.things
中的一个对象来标记该项。这里输入
ng click=“addThing(thing.name,thing.short\u name,thing.info)”
什么是
$scope.thingSelected
??这是一个包含每个添加对象的对象数组,还是一个数组?请给出一个plunker。函数调用中的输入错误和添加类没有正确完成Wero,是的-这里不是100%清楚,但我使用$scope.things创建一个项目列表(使用ng repeat),如果单击一个项目,它既被添加到$scope.thingSelected中,也应该通过添加classIs
$scope.thingSelected
$scope.things
中的一个对象来标记该项。这里输入
ng click=“addThing(thing.name,thing.short\u name,thing.info)”
什么是
$scope.thingSelected
??这是一个包含每个添加对象的对象数组,还是一个数组?请给出一个plunker。函数调用中的输入错误和添加类没有正确完成Wero,是的-这里不是100%清楚,但我使用$scope.things创建一个项目列表(使用ng repeat),如果单击一个项目,它既被添加到$scope.thingSelected中,也应该通过添加classIs
$scope.thingSelected
$scope.things
中的一个对象来标记该项。这里输入
ng click=“addThing(thing.name,thing.short\u name,thing.info)”
什么是
$scope.thingSelected
??这是一个包含每个添加对象的对象数组,还是一个数组?请给出一个plunker。函数调用中的输入错误和添加类没有正确完成Wero,是的-这里不是100%清楚,但我使用$scope.things创建一个项目列表(使用ng repeat),如果单击一个项目,它将被添加到$scope.thingSelected中,并且还应该通过添加一个classAh来标记该项目,我当时的印象是,我不能像那样传递整个物体,不确定我是从哪里得到这个印象的(可能是一些无关的事情出了问题)。。。我想需要一些重写,谢谢你啊,我明白了,我当时的印象是,我不能像那样把一整件东西都传过去,不知道我是从哪里得到这个印象的(可能是一些无关的东西出了问题)。。。我想需要一些重写,谢谢你啊,我明白了,我当时的印象是,我不能像那样把一整件东西都传过去,不知道我是从哪里得到这个印象的(可能是一些无关的东西出了问题)。。。我想需要一些重写,谢谢你啊,我明白了,我当时的印象是,我不能像那样把一整件东西都传过去,不知道我是从哪里得到这个印象的(可能是一些无关的东西出了问题)。。。我想需要一些重写,谢谢