Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
6066 Lượt xem

Hi everybody,

I just started to learn Odoo, and I try to create a snippet for my theme. I added a CSS style for my snippet, but I don't know how to add JS !

In my snippet.xml , I writed this :

<template id="mystyle" name="My style" inherit_id="website.assets_backend">
    <xpath expr="." position="inside">
        <link href="/theme_kissa/static/src/css/style.css" rel="stylesheet" type="text/css"/>
        <link href="/theme_kissa/static/src/js/javascript.js" rel="stylesheet" type="text/javascript"/>
    </xpath>


and in my Javascript.js , this one :

odoo.define('theme_kissa.javascript_nom', function(require) {
"use strict";

var a_variable = require('theme_kissa.javascript_nom.define'); // for this file 'your_module_name.some_name'

a_variable.include({

    fonctionjava: function(args) {
            $(".filter-button").click(function(){
        var value = $(this).attr('data-filter');
       
        if(value == "all")
        {
            //$('.filter').removeClass('hidden');
            $('.filter').show('1000');
        }
        else
        {
//            $('.filter[filter-item="'+value+'"]').removeClass('hidden');
//            $(".filter").not('.filter[filter-item="'+value+'"]').addClass('hidden');
            $(".filter").not('.'+value).hide('3000');
            $('.filter').filter('.'+value).show('3000');
           
        }
    });
   
    if ($(".filter-button").removeClass("active")) {
$(this).removeClass("active");
}
$(this).addClass("active");

    },
});

});


Can you help please? Where is the wrong with this code ? And sorry for my english...

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

This is the correct format for defining js inside xml files

<script type="text/javascript" src="path/to/file.js"></script>

Also js format you are using is compatible from Odoo 9.0 onwards. Please go through the guide Odoo js official doc


Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

How to use Javascript in Odoo 8 ? 


Thank's

Ảnh đại diện
Huỷ bỏ

What is your question exactly? How to add JS files to the theme or is it about the code itself? Please be more specific.

Tác giả

I want to know if the problem is the code of JS or the way by I add the JS in Odoo ...

I took this snippet : https://bootsnipp.com/snippets/featured/portfolio-gallery-with-filtering-category And I wanted to use the JS of this snippet in my code of snippet.js

Tác giả

No one for explain me how to use Javascript in Odoo 8 ?

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 7 16
11592
1
thg 6 15
10742
1
thg 3 17
6118
1
thg 12 24
4870
1
thg 12 20
5149