如何更新角JS JSON文件 [英] how to update json file in Angular js

查看:98
本文介绍了如何更新角JS JSON文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON文件,我读JSON文件并显示它。当我点击一个项目我想更新以JSON的内容。目前我没有任何后台服务就创建了一个JSON文件,并从中读取。我试图更新JSON的值。

I have a json file , I am reading json file and displaying it. when I click on an item I want to update the contents in json. currently I do not have any back end service just created a json file and reading from it. I am trying to update the values in json.

下面是我的code:

在我的服务类:

loadjsonfile:function(){

var promise= $http.get('json/items.json').success(function(response){
itemList = response;
...
...
}

在控制器类:

$scope.itemList = function(){
return service.loadjsonfile();
}

在视图文件:

<div ng-repeat="items in itemList()">
 <div ng-clcik="selectedItem(items)">
  {{item.id}} {{item.status}}
</div>

在这里,当我点击项目item.status应该改变新来检查。如何更新JSON文件?

here , when I click on items item.status should change from new to checked . how to update the json file?

推荐答案

过浏览器的存储器对象角双向绑定作品,它不上的文件。

Angular two-way binding works over browser-memory-object, it does not work on files.

如果您想更新您的JSON文件,你需要自己重写以.json文件,要做到这一点使用的 HTML5 API,用于本地存储

If you want to update your json file, you need to rewrite .json file by yourself, to do that use HTML5 API for Local Storage.

这篇关于如何更新角JS JSON文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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