How to correctly add a jQuery UI autocomplete widget using Backbone.js

前端 未结 4 2177
花落未央
花落未央 2021-02-08 00:53

I am in the process of learning Backbone.js. I currently assume that if one is using Backbone.js then all client-side javascript/jQuery should be integrated with Backbone. From

4条回答
  •  旧巷少年郎
    2021-02-08 01:21

    In my view, the collection with the data is accessed using this.collection, like @saniko i set up the autocomplete in the view's render function:

    render : function() {
        ...
    
        var me = this; //Small context issues
    
        this.$el.find('input.autocompleteSearch').autocomplete({
            source : function(request, response){
                me.collection.on('reset', function(eventname){
                    var data = me.collection.pluck('name');
                    response(data); //Please do something more interesting here!
                });
    
                me.collection.url = '/myresource/search/' + request.term;
                me.collection.fetch();
            }
        });
    
        ...
    },  
    ...
    

提交回复
热议问题