繁体   English   中英

在反应中没有定义“可视化”

[英]'visualize' is not defined no-undef in react

我试图将Visualize.js图表​​嵌入我的React应用程序中,并且出现此错误:“'Visualize'未在react中定义为no-undef”

我也在index.html中导入了visualize.js。 以下代码中指向visualize.js的链接不正确,因为出于保密目的,我将其替换。

如何从服务器导入库并运行“可视化”功能? 谢谢!

import React, { Component } from 'react';
import queryString from 'query-string';  
import {
    api,
    defaultProductQuery,
    Category,
    SortBy
} from './api.js';
import { Page } from './Page.js';

const Option = Select.Option;

export class TopProductsDashBoard extends Component {        
    constructor(props) {
        super(props);
        this.state = {
            data: [],
            product: null,
            loading: true
        };
    }

    componentDidMount() {
        visualize({
            auth: {
                name: "name",
                password: "password"
            }
        }, function(v) {
            //render report from provided resource
            v("#container").report({
                resource: "public/report",
                error: handleError
            });

            //show error
            function handleError(err) {
                alert(err.message);
            }
        });
    }

    onNavigateBack = () => {
        if (this.props.location.state) {
            this.props.history.goBack();
        } else {
            this.props.history.push('/');
        }
    };

    render() {
        return (
            <div>
                <script type='text/javascript' src="http://example.com/jasperserver-pro/client/visualize.js"></script> 
                <div id="container"></div>
            </div>
        );
    }
}

我做的方式:

"use strict";

var React = require("react")

var AnalythicsDashboardView = React.createClass({

    componentDidMount: function () {
        const visualize = window.visualize;
        visualize({
            auth: {
                name: "some_name",
                password: "some_pass",
                organization: "some_org"
            }
        }, function (v) {
            v("#container").dashboard({
                resource: "/public/Workshop/Profit_Dashboard",
                error: handleError
            });

            // show error
            function handleError (err) {
                alert(err.message);
            }
        });
    },

    render: function () {
        return (
            <div id="container" style={{ width: "100%", height: "1000px" }}>
                <div id="dashboard">
                    <div><p>Loading...</p></div>
                </div>
            </div>
        );
    }
});

module.exports = AnalythicsDashboardView;

并在我的index.html中添加以下行:

<script type="text/javascript" src="http://localhost:8081/jasperserver-pro/client/visualize.js"></script>

const visualize = window.visualize;

暂无
暂无

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

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