简体   繁体   English

Javascript / Jquery在Spree中不起作用

[英]Javascript/Jquery not working in Spree

Hey guys I have an application using spree and I need to implement some new javascript to create a new promotion rule. 大家好,我有一个使用spree的应用程序,我需要实现一些新的javascript来创建新的升级规则。 Unfortunately I'm unable to access any js files regardless of where I put them. 不幸的是,无论放置在哪里,我都无法访问任何js文件。 I've even tried overriding sprees files such as promotions.js to implement new functions but it's just not going through. 我什至尝试覆盖sproes文件(例如promotions.js)来实现新功能,但这只是没有完成。 I've tried placing the js file in the following : 我尝试将js文件放在以下文件中:

app/assets/javascript/spree/backend 应用/资产/ javascript /狂欢/后端

vendor/assets/javascript/spree/backend 供应商/资产/ javascript /狂欢/后端

In my partial _product_value.html.erb : 在我的_product_value.html.erb部分中:

<button class='cool'>okay</button>

In promotions.js 在promotions.js中

$('.cool').click(function(event) {
    event.preventDefault()
    alert('donezo');
});

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. 将promotions.js放入app / assets / javascripts / backend,并在同一目录中创建一个新的all.js文件。 I then added.. 然后,我添加了..

 //= require spree/backend/promotions.js

Below //= require_tree . 下面// = require_tree。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM