Html AngularJs如何选择列表中的多个项目,并将它们推送到具有唯一id的对象数组中?
我从2天开始就在做这个任务,我试图将唯一的id对象推送到数组中,但它不起作用,css也不适用于选择和取消选择。 下面是我的代码Html AngularJs如何选择列表中的多个项目,并将它们推送到具有唯一id的对象数组中?,html,css,angularjs,angularjs-directive,angularjs-ng-repeat,Html,Css,Angularjs,Angularjs Directive,Angularjs Ng Repeat,我从2天开始就在做这个任务,我试图将唯一的id对象推送到数组中,但它不起作用,css也不适用于选择和取消选择。 下面是我的代码 <li><a href="" ng-class="{'activeQuestion' :active}" ng-click="selectAnswer('{{ans.choiceID}}')"><choicecontentdesc></choicecontentdesc></a></li>
<li><a href="" ng-class="{'activeQuestion' :active}" ng-click="selectAnswer('{{ans.choiceID}}')"><choicecontentdesc></choicecontentdesc></a></li>
HTML:
<li><a href="" ng-class="{'activeQuestion' :active}" ng-click="selectAnswer('{{ans.choiceID}}')"><choicecontentdesc></choicecontentdesc></a></li>
指令:
<li><a href="" ng-class="{'activeQuestion' :active}" ng-click="selectAnswer('{{ans.choiceID}}')"><choicecontentdesc></choicecontentdesc></a></li>
scope.$parent.$parent.$parent.$parent.selected=[];
scope.selectAnswer = function () {
//alert(scope.id);
if (scope.ansSubmitted) {
return;
}
console.log("posssss",scope.$parent.$parent.$parent.$parent.selected.indexOf(scope.id));
scope.$parent.$parent.$parent.$parent.selectedObj = {
'selectedChoiceId' : scope.id,
'selectedChoiceDesc' : scope.text
};
console.log("obj",scope.$parent.$parent.$parent.$parent.selectedObj);
scope.active = scope.id === scope.$parent.$parent.$parent.$parent.selectedObj.selectedChoiceId;
var pos = scope.$parent.$parent.$parent.$parent.selected.indexOf(scope.id);
console.log("pos",pos);
if (pos == -1) {
scope.$parent.$parent.$parent.$parent.selected.push({
id: scope.$parent.$parent.$parent.$parent.selectedObj.selectedChoiceId,
text: scope.$parent.$parent.$parent.$parent.selectedObj.selectedChoiceDesc,
//datecolor:$scope.color
})
console.log("array1",scope.$parent.$parent.$parent.$parent.selected);
} else {
scope.$parent.$parent.$parent.$parent.selected.splice(pos, 1);
}
有人知道如何实施吗 创建一个please…请问您的
<li><a href="" ng-class="{'activeQuestion' :active}" ng-click="selectAnswer('{{ans.choiceID}}')"><choicecontentdesc></choicecontentdesc></a></li>