javascript - ionic 框架的动态数据

标签 javascript mysql json cordova ionic-framework

我是使用 ionic 框架的新手。 我使用一个示例在 services.js 中的应用程序中显示联系人

angular.module('starter.services', []).factory('Equipements', function() {
    var equipements = [{
        id: 0,
        name: 'Scruff McGruff'
    }, {
        id: 1,
        name: 'G.I. Joe'
    }, {
        id: 2,
        name: 'Miss Frizzle'
    }];
    return {
        all: function() {
            return equipements;
        },
        get: function(equipId) {
            // Simple index lookup
            return equipements[equipId];
        }
    }
})

但我想使用从 MySQL 数据库返回 JSON 数组的资源。

ionic 可以吗?

提前谢谢

最佳答案

是的,这是可能的。

angular.module('starter.services', []).factory('Equipements', function($http) {
    var equipements = {};
    $http({
        method: 'GET',
        url: 'http://example.com/get_all_equipments'
    }).
    success(function(data, status, headers, config) {
        equipements = data;
    });
    return {
        all: function() {
            return equipements;
        }
    }
})

关于javascript - ionic 框架的动态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27420743/

相关文章:

java - 从 Java 创建 JSON

jquery - JQuery 数据表中的动态列名称

python - 如何在 python 3 中将字符串添加到 json 值

javascript - 替代成百上千的 if 语句

mysql - 在heroku上部署node应用程序时如何连接mysql

php - 如何使用 Foreach 循环 Php 添加 ON DUPLICATE KEY UPDATE

python - 如何在 Windows 上使用 Python 3 连接到 MySQL?

Javascript通过对象的属性更新数组对象

javascript - Chart.js - 无法通过 PHP 从 MySQL 获取结果

javascript - Bootstrap-Vue - 使子组件在 b 模态组件内工作