Javascript Angularjs在json临时变量中添加新记录

Javascript Angularjs在json临时变量中添加新记录,javascript,json,angularjs,Javascript,Json,Angularjs,我正在获取当前用户id,并从数据库中获取一些详细信息 $http.post('get-family-list.php', {user_id:user_id}). success(function(data, status) { $localStorage.family = data; }). error(function(data, status) { console.log('Cannot Retrieve Family List');

我正在获取当前用户id,并从数据库中获取一些详细信息

$http.post('get-family-list.php', {user_id:user_id}).
    success(function(data, status) {
      $localStorage.family = data;
    }).
    error(function(data, status) {
      console.log('Cannot Retrieve Family List');  
  });
此代码起作用,然后用户可以在同一视图中添加新记录。我的意思是CRUD操作都在同一个页面中,我在app base controller中调用上述代码。不在CRUD页面中

在积垢控制器中

$scope.family_list = $localStorage.family;
所以现在我的问题是,当用户创建新记录或编辑记录时,我无法更新列表。。我不想再次从服务器获取整个列表。我想向本地存储变量$localStorage.family添加/更新新值

我在insert/updatehttp请求的success函数中编写了这段代码,它不起作用

$scope.family_list[data.id] = {"nric":this.nric,"dob":date_of_birth,"name":this.name,"gender":this.gender,"relationship":this.relationship,"student":this.student};

$localStorage.family = $scope.family_list;
还有我的json值

{"4":{"ID":"4","UID":"26","nric":"sdf","dob":"01\/01\/1990","name":"a","gender":"1","relationship":"1","student":"1","created":"2015-06-03 11:04:29"},"5":{"ID":"5","UID":"26","nric":"aaaa","dob":"01\/01\/1990","name":"aaa","gender":"1","relationship":"1","student":"1","created":"2015-06-03 11:13:21"},"1":{"ID":"1","UID":"26","nric":"ad","dob":"17\/05\/1990","name":"asdf asf","gender":"1","relationship":"1","student":"1","created":"2015-06-02 21:33:59"},"2":{"ID":"2","UID":"26","nric":"ad new","dob":"24\/03\/1984","name":"asdf asf new","gender":"2","relationship":"2","student":"2","created":"2015-06-02 21:46:50"},"3":{"ID":"3","UID":"26","nric":"insert 113","dob":"01\/01\/1990","name":"insert update","gender":"1","relationship":"1","student":"1","created":"2015-06-03 10:41:23"},"6":{"ID":"6","UID":"26","nric":"adfsdf","dob":"01\/01\/1990","name":"sdfsdf","gender":"1","relationship":"1","student":"1","created":"2015-06-03 11:14:20"}}

多亏了所有的

这个.nric等是什么。。?我的意思是为什么
这个
,不应该是
数据.nric
?为什么要创建一个关联数组?如果我理解正确,你所要做的就是$localStorage.family[data.id]=$scope.family_list[data.id];等等,我几分钟后告诉你。。此.nric用于从表单中获取值。等等,我告诉你。你的意思是当$localStorage.family和$scope.family_列表为空时,添加第一项不起作用?只需在控制器顶部初始化它们,如$localStorage.family={}$scope.family_list={};之后,代码应该按原样工作。如果这没有帮助,请向我们展示您文件的全部内容,以便更好地了解工作流。