JQuery / Handlebars error message - Uncaught TypeError: Object [object Object] does not have a 'match' method

I am working on a small training project and ran into a problem that I cannot solve.

I get the following error message on google chromes dev console: -

Uncaught TypeError: Object [object Object] has no method 'match' lexer.nexthandlebars-1.0.0.beta.6.js:364 lexhandlebars-1.0.0.beta.6.js:392 lexhandlebars-1.0.0.beta.6.js:214 parsehandlebars-1.0.0.beta.6.js:227 Handlebars.parsehandlebars-1.0.0.beta.6.js:507 compilehandlebars-1.0.0.beta.6.js:1472 (anonymous function)handlebars-1.0.0.beta.6.js:1481 (anonymous function)scripts.js:103 jQuery.Callbacks.firejquery.js:1046 jQuery.Callbacks.self.fireWithjquery.js:1164 donejquery.js:7399 jQuery.ajaxTransport.send.callback 

Now it appears on error with the following code in handle descriptors

 match = this._input.match(this.rules[rules[i]]); Uncaught TypeError: Object [object Object] has no method 'match' 

So, I take from this that there should be a problem with my code, and not the steering code, even if it is in beta.

Here is the section of code that completely disabled it.

 displayJobInfo: function( e ) { var self = Actors; self.config.jobInfo.slideUp( 300 ); var jobnum = $(this).data( 'job_id' ); $.ajax({ data: { job_id: jobnum } }).then(function( results ) { self.config.jobInfo.html( self.config.JobInfoTemplate( { jobs: results, job_id: jobnum }) ).slideDown(300); }); console.log($(this).data( 'job_id' )); e.preventDefault(); } 

I spent hours trying to work with this on my own, and I have almost the same section of code that works in another part of my site.

A bit of background - I use php to pull the database out of mysql and then query the database based on user input and jquery to overlay the fields back into the page.

+6
source share
3 answers

This happens if you try to compile a template from a jquery element object instead of a string. for instance

 <script id="my-template-script" type="text/template">...</script> 

and then

 var my_template = Handlebars.compile( $("#my-template-script") ); // WRONG 

You can expect it to explode immediately, but it is not. Instead it should be

 var my_template = Handlebars.compile( $("#my-template-script").html() ); 
+9
source

If you get the template as text / html, then your template may be htmlDocument. If you initialize the template as follows, then it will work fine.

 function getTemplate(templateName,context, callback, errorCallback) { var template = {}; template.name = templateName; $.ajax({ url: templateName, timeout: 1000, datatype: "text/javascript", error: function(jqXHR, textStatus, errorThrown) { errorCallback && errorCallback.call(context, textStatus); }, success:function(response, textStatus, jqXHR) { try { template['handlebar'] = Handlebars.compile(jqXHR.responseText); } catch(e) { console.error("error while creating Handlebars script out of template for [", template, e); throw e; } template['rawTemplate'] = jqXHR.responseText; callback && callback.call(context, template); return response; } }); 

}

If you use the response parameter instead of jqHXR.responseText, you will get a “match” not found. I have tried this.

+3
source

match applies only to strings. You must apply it to the input value. If it is a jQuery object, you can use _input.val() otherwise _input.value should work.

On the other hand, as part of the library, you can check what type of data is expected as input and what you are really sending.

null , for example, is an object in javascript, so you probably want to change it on an empty line if the library does not handle it.

+1
source

Source: https://habr.com/ru/post/914199/


All Articles