代码之家  ›  专栏  ›  技术社区  ›  MikeAinOz

如何使用React与PowerBI自定义可视化

  •  0
  • MikeAinOz  · 技术社区  · 8 年前

    我正在尝试将Power-BI-Custom-visualreact示例推进到可以访问react组件中父可视化的数据视图的阶段。 https://github.com/ignatvilesov/powerbi-visuals-react-sample 回答这个问题可能不需要在电源BI自定义视觉专业知识,反应的知识可能是足够的。

    在visual的Update方法中,它创建调用 ReactDOM.render ReactDOM.render(React.createElement(App), this.element);

    ReactDOM.render(React.createElement(App,{options} ), this.element); ,我发现了问题。

    我不明白如何使用道具获取options对象,我尝试了很多方法,下面是我在App.tsx上尝试的一个示例

    module powerbi.extensibility.visual {
        export class App extends React.Component<any,any> {
    
            constructor(props: VisualUpdateOptions) {
                super(props);                            
            }     
            public render() {
    
                var message = "";
                if (this.props == null){
                    message = "no data"
                }
                else
                {
                    message = "got data"
                }
                var message2 = "";
                if (this.props.dataViews == null)
                {
                    message2 = "no dataview"
            }
                else
                {
                    message2 = "got dataview"
                }
            ... 
    

    我得到数据没问题,消息2总是不给我数据视图。任何建议都将不胜感激,我在这方面非常无知,寻求启示:-)

    1 回复  |  直到 8 年前
        1
  •  2
  •   Lukasz    8 年前

    我认为应该尝试将props对象传递给visual.ts中的create元素(在这里创建react应用程序的实例)。像这样:

    ReactDOM.render(React.createElement(App, {"yourProp": "props"}), this.element);
    

    控制台日志道具,因为你现在正在做,你应该看到他们。