问题
Hey guys I have an application using spree and I need to implement some new javascript to create a new promotion rule. Unfortunately I'm unable to access any js files regardless of where I put them. I've even tried overriding sprees files such as promotions.js to implement new functions but it's just not going through. I've tried placing the js file in the following :
app/assets/javascript/spree/backend
vendor/assets/javascript/spree/backend
In my partial _product_value.html.erb :
<button class='cool'>okay</button>
In promotions.js
$('.cool').click(function(event) {
event.preventDefault()
alert('donezo');
});
回答1:
Alright! I figured it out. I wrapped it around a document ready like so...
$(document).ready(function () {
$('.cool').on('click', function() {
alert('donezo');
});
$("#ight").click(function() {
alert('worked');
});
});
Threw promotions.js into app/assets/javascripts/backend and created a new all.js file in the same directory. I then added..
//= require spree/backend/promotions.js
Below //= require_tree .
来源:https://stackoverflow.com/questions/36455245/javascript-jquery-not-working-in-spree