Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.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
Javascript 如何在angularjs的表格单元格中插入多个值_Javascript_Angularjs_Angularjs Ng Repeat - Fatal编程技术网

Javascript 如何在angularjs的表格单元格中插入多个值

Javascript 如何在angularjs的表格单元格中插入多个值,javascript,angularjs,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Ng Repeat,在下表中,在特定日期可以有多个列表。所以对于列表列,给定日期可以有多个列表 我可以在单个单元格中插入多个值,但它会移动我插入多个值的行,请查看 示例:表 日期列表 2016年1月12日。。。。python,angularjs 2016年1月13日。。。。。java、html 数据: $scope.todolists = [{ date: '12/1/2016', list: {python, angularjs} }, { date: '13/1/2016', l

在下表中,在特定日期可以有多个列表。所以对于列表列,给定日期可以有多个列表

我可以在单个单元格中插入多个值,但它会移动我插入多个值的行,请查看

示例:表

日期列表

2016年1月12日。。。。python,angularjs

2016年1月13日。。。。。java、html

数据:

$scope.todolists = [{
    date: '12/1/2016',
    list: {python, angularjs}
}, {
    date: '13/1/2016',
    list: {java, html}
}];
 <tbody>
     <tr ng-repeat="todolist in todolists" >
        <td>{{todolist.date}}</td>
       <td ng-repeat="list in todolist">{{subject}}</td>                                         
     </tr>
 </tbody>
查看:

$scope.todolists = [{
    date: '12/1/2016',
    list: {python, angularjs}
}, {
    date: '13/1/2016',
    list: {java, html}
}];
 <tbody>
     <tr ng-repeat="todolist in todolists" >
        <td>{{todolist.date}}</td>
       <td ng-repeat="list in todolist">{{subject}}</td>                                         
     </tr>
 </tbody>

{{todolist.date}
{{subject}}

我在
ng repeat
内部尝试了
ng repeat
,但它不起作用。所以我的问题是如何在表中的单个单元格中插入多个值。

您的引用是错误的

 <tbody>
     <tr ng-repeat="todolist in todolists" >
        <td>{{todolist.date}}</td>
       <td ng-repeat="list in todolist.list">{{list}}</td>                                         
     </tr>  
 </tbody>

{{todolist.date}
{{list}}
或者,最好是

 <tbody>
     <tr ng-repeat="todolist in todolists" >
        <td>{{todolist.date}}</td>
        <td>
            <span ng-repeat="list in todolist.list">
                  {{list + ($last ? "" : ", ") }}
            </span>                                         
        </td>
     </tr>  
 </tbody>

{{todolist.date}
{{list+($last?”:“,”)}

您的数据未正确声明。应该是:

    $scope.todolists = [{
      date: '12/1/2016',
      list: [
        'python',
        'angularjs'
      ]
    }, {
      date: '13/1/2016',
      list: [
        'java',
        'html'
      ]
    }];
请注意python周围的“”等,该列表应该是一个列表=>[],而不是{}

一个很好的方法是编写一个自定义过滤器:

angular.module("myApp", [])
  .filter('nicelist', function() {
    return function(input) {
      if (input instanceof Array) {
        return input.join(",");
      }
      return input;
    }
  });
然后,您可以使用:

<table>
  <tr ng-repeat="todolist in todolists">
    <td>{{todolist.date}}</td>
    <td>{{todolist.list | nicelist}}</td>
  </tr>
</table>

{{todolist.date}
{{todolist.list | nicelist}}
这是一张工作票

  • 您的
    JSON
    无效。如果要存储不带属性的值,则需要使用
    数组
    ,但不能使用
    对象
    。此外,如果值是
    string
    ,则需要使用逗号将其包装为:
    ['val1','val2',…]
  • 您可以在
    ng repeat
    内部执行
    ng repeat
    操作,但需要迭代正确的属性
    todolist.list
  • 如果模型中没有属性
    subject
    ,则不能使用
    {{subject}
    。因此,在执行类似于
    ng repeat=“todolist.list中的list”
    ng repeat
    时,需要使用
    {{list}
  • 完整代码:

    $scope.todolists = [{
        date: '12/1/2016',
        list: {python, angularjs}
    }, {
        date: '13/1/2016',
        list: {java, html}
    }];
    
     <tbody>
         <tr ng-repeat="todolist in todolists" >
            <td>{{todolist.date}}</td>
           <td ng-repeat="list in todolist">{{subject}}</td>                                         
         </tr>
     </tbody>
    
    angular.module('app',[])。
    控制器('ctrl',函数($scope){
    $scope.todolists=[{date:'12/1/2016',list:['python','angularjs']},{date:'13/1/2016',list:['java','html']}];
    });
    
    
    {{todolist.date}
    {{list}}
    
    可以,但您忘记了列表值之间的逗号。我不认为我忘记了。。但我现在将“to
    @MoshFeu替换为“
    ”。谢谢您提供的答案,我尝试了您的示例,但它无法正常工作。看一下这里的演示,最后一行是班次。我更新了问题,请看。代码运行得很好。。问题在于,您试图为每个id生成多个单元格,而每个todolist中的
    id
    s的数量不同。你想做什么?要在一个单元格中显示它们吗?感谢您提供的答案,我已尝试过,但无法正常工作。看一下这里的演示,最后一行是班次。我更新了问题,请查看。我正在修复它(粘贴的代码中有一个错误)。你的ID不是数组,这是你的问题。你的代码中有很多错误。好像你想把我的解决方案和其他的混合起来。这是您的小提琴的固定版本:。如果有不清楚的地方,请告诉我。谢谢你的回答,我试过了,但效果不好。看一下这里的演示,最后一行是班次。我更新了问题,请看。@geeks,请看我答案的部分版本。不要在
    元素中使用ng repeat,而是在
    {{id+($last?'','')}}
    元素中使用逗号分隔:
    {id+($last?'',')}
    不要在
    td
    上使用
    ng repeat
    ,在
    td
    元素中使用
    span
    ,并在
    span
    上使用repeat,通常不建议在问题正文中包含与代码明显不同的演示链接,因为人们可能会尝试使用演示代码回答问题。其他人在稍后审查问题时可能没有意识到代码的差异,并且难以理解问题和答案。