Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.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 Angular js item.push不是对象_Javascript_Angularjs - Fatal编程技术网

Javascript Angular js item.push不是对象

Javascript Angular js item.push不是对象,javascript,angularjs,Javascript,Angularjs,我试图将数据推送到一个数组,并使用ng repeat显示它,但我得到了一个错误,即itemorg.push不是函数,itempeople.push不是函数。我还需要在调用完成后将两个数组都设为null,因为在显示所有追加的项和显示的项时不设null,我的意思是之前的数据也会显示 $scope.display = function(list, searchid) { $scope.Itemsorg = []; $scope.Items = []; $scope.Itemsp

我试图将数据推送到一个数组,并使用ng repeat显示它,但我得到了一个错误,即itemorg.push不是函数,itempeople.push不是函数。我还需要在调用完成后将两个数组都设为null,因为在显示所有追加的项和显示的项时不设null,我的意思是之前的数据也会显示

$scope.display = function(list, searchid) {
    $scope.Itemsorg = [];
    $scope.Items = [];
    $scope.Itemspeople = [];
    $scope.displayItems = [];
    $scope.Itemsorg = '';
    $scope.Itemspeople = '';
    $scope.Items = '';

    switch (searchid) {

        case 'organisation':

        for (var i = 0; i < list.length; i++) {
          $scope.Itemsorg.push(list[i].relatedEntityInstanceId);
          $scope.Items = $scope.Itemsorg
          break;

         case 'people':
          if (list.length == 0) {
            $scope.Items = '';

          } else if (list.length > 0) {
            for (var j = 0; j < list.length; j++) {

              $scope.Itemspeople.push(list[j].relatedEntityInstanceId);
              $scope.Items = $scope.Itemspeople;

            }
          }
        }
    }
}
$scope.display=函数(列表,搜索ID){
$scope.Itemsorg=[];
$scope.Items=[];
$scope.Itemspeople=[];
$scope.displayItems=[];
$scope.Itemsorg='';
$scope.Itemspeople='';
$scope.Items='';
开关(搜索ID){
个案"组织":
对于(变量i=0;i0){
对于(var j=0;j

我犯的错误请帮助我,朋友们在示例的第6行和第7行中,您将
$scope.Itemsorg
$scope.Itemspeople
定义为空字符串。第8行和第21行后面的
$scope.Items
也是如此

在所有这些行中,您可能指的是空数组:

$scope.Itemsorg = [];
$scope.Itemspeople = [];
$scope.Items = []; // etc.

$scope.Itemspeople=[]
后跟
$scope.Itemspeople='',所以它是一个字符串,而不是数组
String
没有
push
方法。感谢您的回复,然后我如何使其工作。我需要在完成调用后将两个数组都设置为null,因为在显示所有追加的项和显示的项时不设置null,我指的是以前的数据也会显示。如何解决此问题???
与“空数组”不同<代码>[]
是。