完全是Ionic和Angular的新手,需要外部json请求的建议
Complete New to Ionic and Angular, need advice with external json request
我刚从离子开始,我知道这可能非常简单。我一直在阅读如何使用离子和角,但还没能解决这个简单的小任务。
我只是想简单地从外部文件拉json。我仍在阅读文档,但还不能设法弄清楚如何做到这一点。
http://codepen.io/anon/pen/wKwxpX var myApp = angular.module('myApp', ['ionic']);
myApp.controller('MainCtrl', function() {
//instead of hard coded json, I need to get json from an external source here
this.items = [
{title: "Item 1"},
{title: "Item 2"},
{title: "Item 3"},
{title: "Item 4"},
{title: "Item 5"},
]
for (var i = 0; i < 1000; i++)
this.items.push(i);
});
您可以使用$http
调用为外部ajax和内部成功调用绑定结果到$scope
变量。
您还需要在"
双引号包装标题,使其有效json像"title"
标记
<body ng-controller="MainCtrl as main">
<ion-header-bar class="bar-positive">
<h1 class="title">1000 Items</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item collection-repeat="item in main.items">
{{item.title}}
</ion-item>
</ion-list>
</ion-content>
</body>
控制器var myApp = angular.module('myApp', ['ionic']);
myApp.controller('MainCtrl', function($http) {
var main = this
$http.get('data.json').success(function(data){
main.items = data;
})
});
数据。JSON
[{
"title": "Item 1"
}, {
"title": "Item 2"
}, {
"title": "Item 3"
}, {
"title": "Item 4"
}, {
"title": "Item 5"
}]
演示Plunkr
相关文章:
- 如何在 JavaScript 中编辑外部 JSON 文件
- 将外部Json渲染为玉
- 主干从外部json填充集合
- 从外部json代码向amcharts图表添加数据
- Angularjs赢得't从外部json文件中读取
- 带有外部JSON文件的Ionic框架
- 在外部JSON文件中存储对象数组
- 在Javascript或Jquery中,如何将外部json文件作为参数传递给函数
- 解析外部 JSON 文件中的未命名对象
- 如何使用 Javascript 循环遍历外部 JSON 文件数据
- 从外部 JSON 文件创建 JavaScript 变量
- 使用外部 json 文件使用 d3js 创建气泡图
- D3.js外部 JSON 文件
- 我有一个外部 json 文件,比如 abc.json.因为它包含{“记住我”:“Acuérdate”}
- 从 API 到数组的外部 JSON
- 使用 jQuery 从外部 JSON 站点 Singleton 类获取数据
- 从外部 json 文件获取数据
- 在 AngularJS 中使用从 websockets 动态获取的外部 JSON 数据自动更新 DOM
- 如何将外部 JSON 数据从上一个任务中生成的文件传递到任务
- 如何查看外部 JSON 文件