从数组中删除$$ hashKey [英] remove $$hashKey from array

查看:177
本文介绍了从数组中删除$$ hashKey的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$scope.appdata = [{name: '', position: '', email: ''}];

这是我在角度控制器中创建的数组.

This is the array which I created in angular controller.

然后我使用push方法将一些值插入到数组中

Then I inserted some values in to array by using push method:

$scope.appdata.push({name: 'jenson raby', position: '2', email: 'jensonraby@gmail.com'});

这是插入后的数组值:

$$hashKey:"00F",name:"jenson raby",position:"2",email:"jensonraby@gmail.com",

在插入后,在数组中添加了额外的$$hashKey,但是我需要从数组中删除它.

Here an extra $$hashKey has been added to the array after insertion, but I need to remove this from array.

推荐答案

根据您的评论,您需要将数组插入数据库中,我假设您正在将其转换为JSON字符串,然后保存它到数据库.如果不正确,请告诉我,我将看看是否可以修改此答案.

Based on your comment that you need to insert the array into the database, I'm going to assume that you are converting it a JSON string and then saving it to the DB. If that's incorrect, let me know and I'll see if I can revise this answer.

在将数组转换为JSON时,有两个选项可用于修改数组.第一个是 angular.toJson ,这是一种便捷的方法,它会自动删除带有在序列化数组(或对象)之前,以前导$$开头.您将像这样使用它:

You have two options for modifying your array when converting it to JSON. The first is angular.toJson, which is a convenience method that automatically strips out any property names with a leading $$ prior to serializing the array (or object). You would use it like this:

var json = angular.toJson( $scope.appdata );

如果需要更精细的控制,则应使用另一个选项,它是内置

The other option, which you should use if you need more fine grained control, is the replacer argument to the built-in JSON.stringify function. The replacer function allows you to filter or alter properties before they get serialized to JSON. You'd use it like this to strip $$hashKey:

var json = JSON.stringify( $scope.appdata, function( key, value ) {
    if( key === "$$hashKey" ) {
        return undefined;
    }

    return value;
});

这篇关于从数组中删除$$ hashKey的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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