Javascript/Jquery在Spree中不起作用 [英] Javascript/Jquery not working in Spree

查看:103
本文介绍了Javascript/Jquery在Spree中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我有一个使用spree的应用程序,我需要实现一些新的javascript来创建新的升级规则.不幸的是,无论放置在哪里,我都无法访问任何js文件.我什至尝试覆盖sproes文件(例如promotions.js)来实现新功能,但这只是没有完成.我尝试将js文件放在以下位置:

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

app/assets/javascript/spree/backend

供应商/资产/javascript/spree/后端

vendor/assets/javascript/spree/backend

在我的_product_value.html.erb部分中:

In my partial _product_value.html.erb :

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

在Promotions.js中

In 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');
    });
 });

将promotions.js放入app/assets/javascripts/backend,并在同一目录中创建一个新的all.js文件.然后,我添加了..

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

下面//= require_tree

Below //= require_tree .

这篇关于Javascript/Jquery在Spree中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆