我在我的JSX文件中使用了一个组件,并且我将属性值传递给此组件,如下所示:
anything.jsx
import Example from '/containers/example.js'
class Anything extends Component {
render() {
return (
<Example type='article' />
)
}
}
在下面看到,组件通过容器填充数据。现在我需要获取该容器中的属性值,以将其作为订阅值传递。
该组件的值为type
article
。最后,我需要在订阅中获得此值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)
答案 0 :(得分:1)
尝试更改为createContainer((props) => { console.log(props) ...}