anjularjs推动价值嵌套纳克重复 [英] anjularjs push value to nested ng-repeat

查看:166
本文介绍了anjularjs推动价值嵌套纳克重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NG重复嵌套在另一个NG-重复之内。我想一些值推到第二排单击按钮时

 < D​​IV NG重复=车辆vehicleList>
  < D​​IV> {{vehicle.number}}< / DIV>
  <输入名称=addNameVALUE =添加NG点击=addVehicle(车)
  < D​​IV NG重复=,在vehicle.category所属分类>
    < D​​IV> {{categoryList.name}}< / DIV>
  < / DIV>
< / DIV>


 我试着以下code,但它不工作
$ scope.vehicleList = [];$ scope.addVehicle =功能(){
 $ scope.vehicleList.push({
   类别:'车'
 });
}

谁能帮我在这。谢谢


解决方案

 < D​​IV NG重复=车辆vehicleList>
  < D​​IV> {{vehicle.number}}< / DIV>
  <输入名称=addNameVALUE =添加NG点击=addVehicle($指数,汽车)>
  < D​​IV NG重复=,在vehicle.category所属分类>
    < D​​IV> {{categoryList.name}}< / DIV>
  < / DIV>
< / DIV>$ scope.vehicleList = [];$ scope.addVehicle =功能(索引,车){
 $ scope.vehicleList [指数] .category.push({
   名称:车辆
 });
};

I have an ng-repeat nested within another ng-repeat. I want to push some values to the second array when the button is clicked

<div ng-repeat="vehicle in vehicleList">
  <div>{{vehicle.number}}</div>
  <input name="addName" value="add" ng-click="addVehicle(vehicle)"
  <div ng-repeat="categoryList in vehicle.category">
    <div>{{categoryList.name}}</div>
  </div>
</div>


I tried following code but it's not working
$scope.vehicleList=[];

$scope.addVehicle = function(){
 $scope.vehicleList.push({
   category:'car'
 });
}

Can anyone help me on this. Thanks

解决方案

<div ng-repeat="vehicle in vehicleList">
  <div>{{vehicle.number}}</div>
  <input name="addName" value="add" ng-click="addVehicle($index, vehicle)">
  <div ng-repeat="categoryList in vehicle.category">
    <div>{{categoryList.name}}</div>
  </div>
</div>

$scope.vehicleList = [];

$scope.addVehicle = function(index, vehicle) {
 $scope.vehicleList[index].category.push({
   name: vehicle
 });
};

这篇关于anjularjs推动价值嵌套纳克重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆