javascript - ReactJS:如何获取组件容器中的属性?

标签 javascript reactjs meteor

我在 JSX 文件中使用一个组件,并将属性值传递给该组件,如下所示:

anything.jsx

import Example from '/containers/example.js'

class Anything extends Component {
    render() {
        return (
            <Example type='article' />
        )
    }
}

在下面您可以看到,该组件通过容器填充了数据。现在我需要获取该容器中的属性值,以将其作为订阅值传递。

该组件具有typearticle。最后,我需要在订阅中获取此值,例如 Meteor.subscription('exampleDetail', mainID, 'article')。我如何传递该值?

示例组件 (components/example.jsx)

export default class Example extends Component {
    constructor(props) {
        super(props)
    }

    render() {
        const   { type } = this.props

        console.log(type);
    }
}

示例容器 (containers/example.js)

import Example from '../components/example.jsx'

export default createContainer(() => {
    const   mainID       = Session.get('mainID'),
            // ??? How to get type value? 
            subscription = Meteor.subscribe('exampleDetail', mainID, type)

    loading  = !subscription.ready()
    results  = Collection.find().fetch()

    return { results, loading }
}, Example)

最佳答案

尝试更改为 createContainer((props) => { console.log(props) ...}

关于javascript - ReactJS:如何获取组件容器中的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44430602/

相关文章:

javascript - 在 JavaScript 中拆分字符串

javascript - Ajax - 更新内容时浏览器滞后

javascript - 如何在 React JS 中配置 Ckeditor 工具栏?

javascript - .findOne 在 Iron Router Route 的数据属性中工作,但 .find 不工作?

javascript - Bootstrap 选项卡和 Meteor

javascript - addRule/insertRule 在本地不工作

javascript - 如何设置临时填充?

reactjs - Redux 应用程序状态通过 url -> 查询参数

javascript - 从 javascript 调用 React 组件函数

eclipse - 添加 Meteor 的 api 以在 Eclipse 或 Aptana 中进行开发