D
D
Danila2015-11-13 14:09:49
MySQL
Danila, 2015-11-13 14:09:49

How to make updated json in mobile app?

Hello.
The question is. There is a mobile application (ionic). Since it cannot work directly with the database, the server returns json with the necessary parameters.
In the application, it is written to the resource.json file
. How can I make the application already packaged in the application receive and update new values?
PS Comments like write on the native - are not welcome, I would be happy to, but the customer gave the technical specification and it is necessary to do it
Transmits such values ​​-

{
  "categories": [
    {
      "id": 11,
      "title": "Chocolate",
      "items": [1,2,3,4,5,6,7,8,9,10,11,12]
    },
"items": [
  {
    "id": 12,
    "title": " Elegance Dark Chocolate",
    "article": "R-004",
    "description": "Cocoa content: 60%",
    "img": "img/content/products/Elegance_Dark_60.png",
    "item_weight": "100",
    "pack_weight": "4",
    "packing": "40 x 168bags",
    "alcohol": false,
    "ingredients": "",
    "dimensions": "315x240x117",
    "time": "18 months",
    "store": "Keep in a cool dry place."
  },

In application it is caused I cause so.
<h3 class="search-results padding-horizontal" ng-show="filter.query">Search results for "{{filter.query}}":</h3>
        <div ng-repeat="cat in getCategories() | filter: categoryFilter track by cat.id" class="item-divider">
            <h1>{{cat.title}}</h1>
            <ion-list show-delete="shouldShowDelete"
                      show-reorder="shouldShowReorder"
                      can-swipe="listCanSwipe"
                      class="list-borderless">
                <ion-item ng-repeat="(id, item) in getItems(cat.items) | filter : itemsFilter | orderBy : filter.orderBy"
                          ng-class="{expanded: isExpanded(item.id)}">
                    <div class="row" ng-click="expandItem(item.id, true)">
                        <div ng-class="{'col-50': isExpanded(item.id), 'col-33': !isExpanded(item.id)}">
                            <img class="added" src="img/ic_added_green_36dp.svg" ng-show="inOrder(item.id)">
                            <!--<i class="icon added" ng-show="inOrder(item.id)"></i>-->
                            <img ng-src="{{item.img}}">
                        </div>
                        <div ng-class="{'col-50': isExpanded(item.id), 'col-67': !isExpanded(item.id)}">
                            <span class="article">{{item.article}}</span>
                            <h3>{{item.title}}</h3>
                            <p>{{item.description}}</p>
                            <p class="packaging" ng-hide="isExpanded(item.id)">
                                <i class="icon calm ion-cube"></i>
                                {{item.packing}}
                            </p>
                        </div>
                    </div>
                    <div class="detail" ng-show="isExpanded(item.id)">
                        <dl class="row">
                            <dt class="col-50">Ingredients:</dt>
                            <dd class="col-50" ng-bind-html="nl2br(item.description)"></dd>
                        </dl>
                        <div class="row spec">
                            <div class="col">
                                <i class="icon calm ion-cube"></i>
                                {{item.packing}}
                            </div>
                            <div class="col">
                                <i class="icon calm ion-arrow-resize"></i>
                                {{item.dimensions}}
                            </div>
                            <div class="col">
                                <i class="icon calm ion-android-time"></i>
                                {{item.time}}
                            </div>
                        </div>

$scope.getCategories = function() {
            return $scope.categories.filter(function(item) {
                if ($scope.filter.enableCategories && $scope.filter.categories.length) {
                    return $scope.filter.categories.indexOf(item.id) !== -1;
                }
                return true;
            });
        };

        $scope.getItems = function(id) {
            if (!angular.isArray(id)) {
                id = [id];
            }
            $scope.filter.ids = id;
            return $scope.items.filter(function (item) {
                return $scope.filter.ids.indexOf(item.id) !== -1;
            });
        };

.factory('DataProvider', function($http, $q) {
        var data = [];
        return {
            all: function(){
                var dfd = $q.defer();
                $http.get("resource.json").then(function(response){
                    data = response.data;
                    dfd.resolve(data);
                });
                return dfd.promise;
            }
        }
    })

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Danila, 2015-11-13
@lega111

Understood.
santoshshinde2012.blogspot.com/2015/03/reading-jso...
jmdobry.github.io/angular-cache/guide.html
stackoverflow.com/questions/16930473/angularjs-fac...

E
egor_nullptr, 2013-12-12
@egor_nullptr

Please show the structure of the tables.

E
egor_nullptr, 2013-12-12
@egor_nullptr

You can try adding a composite key from (param, g_id, x, y). This will slightly speed up the query. But with the planned volumes, you will not be able to get a very fast sample, because the aggregate functions must iterate over each record from the result (and this will give you Using temporary and Using filesort in explain). I advise you to either use caching (wait once for a long query in advance, then use the result for N minutes), or look towards MongoDB and MapReduce.

S
svd71_1, 2013-12-13
@svd71_1

SELECT
    AVG(`d`.`x`),
    SUM(`d`.`y`)
FROM `data_table` AS `d`,  `group_table` AS `g`
WHERE
    `d`.`param`	= 1
    and
    `d`.`g_id` = `g`.`id`
GROUP BY `g`.`group_column`

L
Leonid, 2013-12-27
Gatalsky @mgnstudio

Since you, as a result, use only data from the data_table table, then I don’t see the point in join at all
Write as follows

SELECT
    AVG(d.x),
    SUM(d.y)
FROM data_table AS d
WHERE EXISTS (SELECT 1 FROM group_table AS g WHERE g.id =d.g_id ) AND d.param = 1
GROUP BY g.group_column

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question