samedi 21 octobre 2017

Ember.js - Uncaught SyntaxError: Unexpected identifier

I can't seem to correct the error in the console. My code searches the text files for a query term. If the query term is present, I want the query term in the text to be highlighted. Not able to figure out this.

  var App = Ember.Application.create();   
    App.Router.map(function() {
      // index route is created by default
    });

    App.IndexController = Em.Controller.extend({
        actions: {
            doSearch: function() {
                var self = this;
                self.set('results', null);
                Em.$.get('/patients/search?query='+this.get('searchText')).then(function(data) {
                    for (var i=0;i<data.length;i++) {
                        var docs = data[i].documents;
                        var newDocs = [];
                        for (var j=0;j<docs.length;j++) {
                            parts = docs[j].split(":::");
                            newDocs.push({
                                title: parts[0],
                                date: parts[1],
                                contents: parts[2]
                            });
                        }
                        data[i].documents = newDocs;
                    }
                    self.set('results', data);
                });     
            }
        },

                var queryTerm = this.get('searchText');      //ERROR IN THIS LINE
                Ember.Handlebars.helper('highlightSearchTerm', function (text, queryTerm) {
                    var highlightedText = text.replace(new RegExp(queryTerm, 'gi'), function (str) {
                    return '<mark>' + str + '</mark>';
                });
            return new Ember.Handlebars.SafeString(highlightedText);
            });  
    });




Aucun commentaire:

Enregistrer un commentaire