ReferenceError: _ is not defined

匿名 (未验证) 提交于 2019-12-03 01:59:02

问题:

I am using a jQuery based WordPress Twitter widget and receive the error "ReferenceError: _ is not defined".

Am not sure how to declare the variable "_".

Here is the widget:

' ); } document.getElementById('twitter_update_list_').innerHTML = statusHTML.join(''); var template = '\ \ \ \ \ '; jQuery( _.template( template, { user: twitters[0].user } )).insertAfter('.bizsteam_twitter ul'); } function relative_time(time_value) { var values = time_value.split( " " ); time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3]; var parsed_date = Date.parse(time_value); var relative_to = (arguments.length > 1) ? arguments[1] : new Date(); var delta = parseInt((relative_to.getTime() - parsed_date) / 1000); delta = delta + (relative_to.getTimezoneOffset() * 60); if (delta !]]>

Firebug states that the line of code with the error is:

jQuery( _.template( template, { user: twitters[0].user } )).insertAfter('.bizsteam_twitter ul'); 

Any help would be greatly appreciated

回答1:

Your widget has Underscore.js/LoDash.js as dependency.

You can get them here: underscore, lodash

Try prepending this to your code, so you can see if it works:



回答2:

You can install it by bower:

Node.js npm install underscore Meteor.js meteor add underscore Require.js require(["underscore"], ... Bower bower install underscore Component component install jashkenas/underscore 

Here's the link to the oficial page http://underscorejs.org/



回答3:

i was facing the same problem in the wp-admin section of the site. I enqueued the underscore script cdn and it fixed the problem.

function kk_admin_scripts() {     wp_enqueue_script('underscore', '//cdnjs.cloudflare.com/ajax/libs/lodash.js/0.10.0/lodash.min.js' ); } add_action( 'admin_enqueue_scripts', 'kk_admin_scripts' ); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!