在角形物体中推动新元素

时间:2017-10-26 09:39:04

标签: angularjs arrays

Hy,所以我有这段代码:

  angular.forEach(parentsId, function(parentId, key) {
    $scope.getContentByParent("Courses",parentId,function(data){

      $scope.Courses.push(data);

    });
  });

  $scope.getContentByParent = function(table,parentId,callback) {

  var data = new FormData();
  data.append('table', table);
  data.append('parentId', parentId);

  $http.post('../server/Model/content/get_content_by_parent.php', data, {
    transformRequest: angular.identity,
    headers: {'Content-Type': undefined}
  })
   .then(function (data) {
     data = data.data;
     callback(data);
    });
   };

和html

 <div class="col-xs-12 col-sm-12" ng-repeat="Course in Courses">
      <div class="ribbon ribbon_primary">
        <div class="ribbon__title">
          {{Course.Name}}
        </div>
        <div class="ribbon__content" ng-bind-html="Course.Description">
        </div>
      </div>
    </div>

所以问题是,当我在对象中推送一个新元素时,它将它作为数组推送,如下所示:

 [Log] Array (2) (home-controller.js, line 23)
    0 [Object] (1)
    1 [Object] (1)

  Array Prototype

如何将其作为新的对象元素推送?

1 个答案:

答案 0 :(得分:0)

我想我明白了:

try{}catch{}