Javascript/Jquery not working in Spree

烈酒焚心 提交于 2020-01-17 10:32:48

问题


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

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