N
N
Nikolai2016-04-27 14:13:40
JavaScript
Nikolai, 2016-04-27 14:13:40

How to move variable to serializer from event handler?

There is code in the template (pagination):

<ul class="pagination"> 
    {{#each item in meta.pagination}}
     <li {{action "newPage"  item}}><a href="#">{{item}}</a></li> 
    {{/each}}
</ul>

Based on How to process response (pagination) from Django REST framework in EmberJS?
Controller code:
App.ArticlesController = Ember.ArrayController.extend({
    needs: ['application'],
    queryParams: ['offset'],
    offset: 0,

    actions: {

        //....
        newPage: function(item) {

            var self = this,
                offset = 0;
            if (item == 1) {
                offset = -1;
            } else {
                offset = (item * 10) - 10;
            } // end if

           var page = 5;
            // вот здесь нужно как то передать  переменную page в серриализатор
           //  типа this.store.set("page", page); , но так не работает

            self.transitionToRoute('articles', {
                queryParams: {
                    "offset": offset
                }
            });

        }


    },
    makeAction: function(widget, params) {
        'use strict';
        var _this = this;
        //var widget = this.get('content');
        var adapter = this.container.lookup('adapter:application');

        adapter.ajax(this.buildUrl(adapter, widget), 'POST', {
                data: params
            })
            .finally(function(response) {
                widget.reload();
            });
    }

});

Part of the serializer code:
extractMeta: function(store, type, payload) {

var page = 1;

   // здесь как то принять page
  // типа page = store.get("page"); , но так не работает

    var pagination = [1,2,3,4,5,6,7,8,9,10]; 

    if (payload && payload.next && payload.previous && payload.count) {
      store.setMetadataFor(type, { next:payload.next, previous:  payload.previous, count: payload.count, page: page, pagination: pagination });  // sets the metadata for "post"
    }
  },

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question