Customizing the drop down result

54 views
Skip to first unread message

Suriya Prakash .

unread,
May 9, 2014, 5:26:53 AM5/9/14
to sel...@googlegroups.com
how can i customize the dropdown result of select2 as you mentioned in the

link : http://ivaynberg.github.io/select2/#ajax

i used the following code:
HTML:
<input type="text" id="itemList" placeholder="Type to search" item/>

Angular Directive:
myApp.directive('item', function($log, $compile) {
    return {
        restrict: 'A',
        link: function($scope, element) {
            $('#itemList').select2({
                minimumInputLength: 0,
                placeholder: 'Search',
                ajax: {
                    url: "http://www.weighttraining.com/sm/search",
                    dataType: 'jsonp',
                    quietMillis: 100,
                    data: function(term, page) {
                        var a = {
                            types: ["exercise"],
                            limit: -1,
                            term: term
                        };
                        console.log(JSON.stringify(a));
                        return a;
                    },
                    results: function(data, page) {
                        return {
                            results: data.results.exercise
                        }
                    }
                },
                formatResult: function(exercise) {
                    return "<div class='select2-user-result'>" + exercise.term + "</div> <span>jdfbgkfdjbgkjfdg</span>";
                },
                formatSelection: function(exercise) {
                    return exercise.term;
                },
                initSelection: function(element, callback) {
                    var elementText = $(element).attr('data-init-text');
                    callback({
                        "term": elementText
                    });
                }
            });
        }
    };
});

but it produce only the error.
how to solve it?
--
Thanks..
suriya.g


Reply all
Reply to author
Forward
0 new messages