如何将javascript插入xml(网站)ODOO

时间:2017-01-03 09:01:08

标签: javascript xml odoo-8

我想从网站下载多张图片,请查看我的javascript和xml代码,我的代码有什么问题?
如何将javascript插入xml?

这是我的javascript代码

var zip = new JSZip();
var count = 0;
var zipFilename = "zipFilename.zip";
var urls = [    
    'http://weedo.sgeede.com/website/image/product.template/376_339fb36/image',
    'http://dota-everyday.com/support/image',
    'http://dota-everyday.com/omniknight/image'
];

urls.forEach(function(url){
    var filename = "filename";
    // loading a file and add it in a zip file
    JSZipUtils.getBinaryContent(url, function (err, data) {
        if(err) {
            throw err; // or handle the error
        }
        zip.file(filename, data, {binary:true});
        count++;
        if (count == urls.length) {
            var zipFile = zip.generate({type: "blob"});
            saveAs(zipFile, zipFilename);
        }
    });
});

这是我的xml

<a href="#" onclick="urls();">Download</a>

2 个答案:

答案 0 :(得分:1)

要将Javascript插入网站xml,您需要创建一个继承网站资产的记录模板,如下所示 -

<template id="custom_assets" inherit_id="website.assets_frontend" name="Custom Assets">
    <xpath expr="." position="inside">
        <script type="text/javascript" src="/...path to your custom js file"></script>
    </xpath>
</template>

答案 1 :(得分:1)

你的最终JS会像 -

odoo.define(['jszip', 'ods'], function (jszip, ods) {
"use strict";
    var zip = new JSZip();
    var count = 0;
    var zipFilename = "zipFilename.zip";
    var urls = [    
       'http://weedo.sgeede.com/website/image/product.template/376_339fb36/image',
       'http://dota-everyday.com/support/image',
      'http://dota-everyday.com/omniknight/image'
    ];

urls.forEach(function(url){
    var filename = "filename";
    // loading a file and add it in a zip file
    JSZipUtils.getBinaryContent(url, function (err, data) {
    if(err) {
        throw err; // or handle the error
    }
    zip.file(filename, data, {binary:true});
    count++;
    if (count == urls.length) {
        var zipFile = zip.generate({type: "blob"});
        saveAs(zipFile, zipFilename);
    }
});

}); });