Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html AngularJs如何选择列表中的多个项目,并将它们推送到具有唯一id的对象数组中?_Html_Css_Angularjs_Angularjs Directive_Angularjs Ng Repeat - Fatal编程技术网

Html AngularJs如何选择列表中的多个项目,并将它们推送到具有唯一id的对象数组中?

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>

我从2天开始就在做这个任务,我试图将唯一的id对象推送到数组中,但它不起作用,css也不适用于选择和取消选择。 下面是我的代码

 <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…请问您的
  • 在ng repeat内吗?您好kulbhushan,是的
  • 在ng repeat内。然后您可以传递$$hasKey属性,该属性总是唯一的,并通过Angle添加,ng click=“selectAnswer(ans.$$hasKey)”。它缺少太多信息,首先不要在ng click selectAnswer中使用大括号(“{ans.choiceID}”)->SelectAns(ans.choiceID). 然后使用您发送的参数在控制器内选择Answer。创建一个please…您的
  • 是否在ng repeat内?嗨,kulbhushan,是的
  • 在ng repeat内。然后您可以传递始终唯一并通过Angular添加的$$hasKey属性,ng click=“selectAnswer(ans.$$hasKey)”。它缺少太多信息,首先不要在ng中使用大括号,单击selectAnswer({{ans.choiceID}}')->selectAnswer(ans.choiceID)。然后使用您发送的参数在控制器内选择Answer。
     <li><a href=""  ng-class="{'activeQuestion' :active}"  ng-click="selectAnswer('{{ans.choiceID}}')"><choicecontentdesc></choicecontentdesc></a></li>