How to load remote data of "Select2" with "Iron-router"?


#1

I want to load remote data of select2 with iron-router

// client
$('[name="addressId"]').select2({
        ajax: {
            url: Router.url('sample.remoteAddress'),
            type: 'GET',
            dataType: 'json',
            delay: 250,
            data: function (params) {
                var query = {
                    term: params
                };

                return query;
            },
            processResults: function (data) {
                return {
                    results: data
                };
            },
            cache: true
        },
        minimumInputLength: 1
    });


// Common
Router.route('sample/remoteAddress', {
    name: 'sample.remoteAddress',
    where: 'server'
}).get(function () {
    var q = this.params.query;

    console.log(q.term);

    var items= [
        {id: 'A', text: 'A'},
        {id: 'B', text: 'B'}
    ];

    this.response.end(JSON.stringify(items));
});

but don’t know about declare router.
Please help me.


#2

My Meteorpad code here.