【发布时间】:2017-03-15 01:19:21
【问题描述】:
我还是 AngularJS 的新手,到目前为止我已经成功地从我的控制器中的 JSON 获取数据
var testAppApp = angular.module('testAppApp', []);
testAppApp.controller('SimpleController', function ($scope, $http) {
$http.get('data/data.json')
.then(function(takeprocess) {
$scope.customers = takeprocess.data.records;
});
});
这是我的 JSON 格式
{
"records": [
{
"Name": "Alfreds Futterkiste",
"City": "Berlin",
"Country": "Germany"
},
{
"Name": "Ana Trujillo Emparedados y helados",
"City": "México D.F.",
"Country": "Mexico"
},
............
}
我的 index.html
<div ng-controller="SimpleController">
Search <input type="text" ng-model="filter.name" />
<ul>
<li ng-repeat="cust in customers | filter:filter.name | orderBy:'No'">
{{$index +1}} - {{cust.Name}} - {{cust.City}} - {{cust.Country}}</li>
</ul>
Adding New Customer <br/>
Name: <br/>
<input type="text" ng-model="Name" /><br/>
City: <br/>
<input type="text" ng-model="City" /><br/>
Country: <br/>
<input type="text" ng-model="Country" /><br/>
<button ng-click="addCustomer(Name, City, Country)">Add Customer</button>
</div>
我想创建函数 addCustomer 来发布数据,并且(也许)将数据存储到 JSON 中,但我不知道如何创建函数......在很多方面,有些人说 angularJS 是前端框架,它可以'不要将数据直接存储到 JSON。请建议我提出一个观点,就我而言,我想将新数据放入列表并永久保存
【问题讨论】:
-
直接存储 JSON 是什么意思?使用 Angular,您可以将创建的 JSON 发送到后端,但后端不是 Angular 的一部分 - 它可以用多种语言创建。 AngularJS 只是前端
-
从技术上讲,如果您的网络服务器支持WebDAV,您可以这样做,但这会带来一个巨大的安全漏洞,而且大多数托管公司不会打开这些漏洞。
-
感谢大家的帮助,我的问题在技术上没有必要,但我很困惑我该怎么办,看来我应该将我的 angularJS 与其他后端语言结合起来。
标签: javascript angularjs json