Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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_Arrays - Fatal编程技术网

Javascript Angularjs删除具有空字段的对象

Javascript Angularjs删除具有空字段的对象,javascript,angularjs,arrays,Javascript,Angularjs,Arrays,如果我的范围内有这样一个变量: $scope.myListOLD = [ { title: "First title", content: "First content" }, { title: "Second title", content: "" }, { title: "Third title", content: "" }, { title: "Fourth title", content: "Fourt

如果我的范围内有这样一个变量:

$scope.myListOLD = 
      [ 
        { title: "First title", content: "First content" }, 
        { title: "Second title", content: "" },
        { title: "Third title", content: "" }, 
        { title: "Fourth title", content: "Fourth content" }  
       ];
如何创建一个新的范围变量来删除特定字段上的任何空值?(在本例中为内容)

使用

函数removeIfStringPropertyEmpty(arr,字段){
返回arr.filter(函数(项){
返回项[field]的类型=='string'&&item[field]。长度>0;
});
}
var$scope={“myListOLD”:[{“title”:“First title”,“content”:“First content”},{“title”:“Second title”,“content”:“},{“title”:“Third title”,“content”:“},{“title”:“Third title”,“content”:“Third content”},{“title”:“Third title”,“content”:“Third content”},};
$scope.myListNEW=removiefstringpropertyEmpty($scope.myListOLD,'content');
log($scope.myListNEW)使用

函数removeIfStringPropertyEmpty(arr,字段){
返回arr.filter(函数(项){
返回项[field]的类型=='string'&&item[field]。长度>0;
});
}
var$scope={“myListOLD”:[{“title”:“First title”,“content”:“First content”},{“title”:“Second title”,“content”:“},{“title”:“Third title”,“content”:“},{“title”:“Third title”,“content”:“Third content”},{“title”:“Third title”,“content”:“Third content”},};
$scope.myListNEW=removiefstringpropertyEmpty($scope.myListOLD,'content');
log($scope.myListNEW)
var-app=angular.module('app',[]);
应用程序控制器('homeCtrl',函数($scope){
$scope.myListOLD=
[ 
{标题:“第一个标题”,内容:“第一个内容”},
{标题:“第二个标题”,内容:},
{标题:“第三个标题”,内容:},
{标题:“第四标题”,内容:“第四内容”}
];
$scope.myListNEW=[];
angular.forEach($scope.myListOLD,函数(值,键){
如果(value.content!==“”)
$scope.myListNEW.push(值);
});
log($scope.myListNEW);
});

var-app=angular.module('app',[]);
应用程序控制器('homeCtrl',函数($scope){
$scope.myListOLD=
[ 
{标题:“第一个标题”,内容:“第一个内容”},
{标题:“第二个标题”,内容:},
{标题:“第三个标题”,内容:},
{标题:“第四标题”,内容:“第四内容”}
];
$scope.myListNEW=[];
angular.forEach($scope.myListOLD,函数(值,键){
如果(value.content!==“”)
$scope.myListNEW.push(值);
});
log($scope.myListNEW);
});


工作得很好!谢谢工作得很漂亮!谢谢
$scope.myListNEW = 
      [ 
        { title: "First title", content: "First content" }, 
        { title: "Fourth title", content: "Fourth content" }  
       ];