反应性使用“;inProgress团队/反应原生流星“;Meteor 1.3中
Reactive usage of "inProgress-team/react-native-meteor" in Meteor 1.3
我在react native(0.23)中有一个项目,Meteor 1.3作为后端,我想显示一个联系人项目列表。当用户单击联系人项目时,我希望在该项目前面显示一个复选标记。
对于Meteor DDP的连接,我使用了Progress team/react native Meteor中令人敬畏的库。
import Meteor, { connectMeteor, MeteorListView, MeteorComplexListView } from 'react-native-meteor';
class ContactsPicker extends React.Component {
constructor(props) {
super(props);
this.state = {
subscriptionIsReady: false
};
}
componentWillMount() {
const handle = db.subscribe("contacts");
this.setState({
subscriptionIsReady: handle.ready()
});
}
render() {
const {subscriptionIsReady} = this.state;
return (
<View style={gs.standardView}>
{!subscriptionIsReady && <Text>Not ready</Text>}
<MeteorComplexListView
elements={()=>{return Meteor.collection('contacts').find()}}
renderRow={this.renderItem.bind(this)}
/>
</View>
);
}
第一个问题是,subscriptionIsReady在返回true后不会触发重新渲染。我如何等待订阅准备就绪并更新模板?
我的第二个问题是,单击列表项会更新状态,并且应该显示一个复选标记,但MeteorListView只有在dataSource发生更改时才会重新渲染。是否有任何方法可以在不更改/更新dataSource的情况下强制重新渲染?
编辑1(解决方案1):
感谢@user1078150提供有效的解决方案。这里是完整的解决方案:
'use strict';
import Meteor, { connectMeteor, MeteorListView, MeteorComplexListView } from 'react-native-meteor';
class ContactsPicker extends React.Component {
getMeteorData() {
const handle = Meteor.subscribe("contacts");
return {
subscriptionIsReady: handle.ready()
};
}
constructor(props) {
super(props);
this.state = {
subscriptionIsReady: false
};
}
componentWillMount() {
// NO SUBSCRIPTION HERE
}
renderItem(contact) {
return (
<View key={contact._id}>
<TouchableHighlight onPress={() => this.toggleSelection(contact._id)}>
<View>
{this.state.selectedContacts.indexOf(contact._id) > -1 && <Icon />}
<Text>{contact.displayName}</Text>
</View>
</TouchableHighlight>
</View>
)
}
render() {
const {subscriptionIsReady} = this.data;
return (
<View>
{!subscriptionIsReady && <Text>Not ready</Text>}
<MeteorComplexListView
elements={()=>{return Meteor.collection('contacts').find()}}
renderRow={this.renderItem.bind(this)}
/>
</View>
);
}
}
connectMeteor(ContactsPicker);
export default ContactsPicker;
你必须这样做:
getMeteorData() {
const handle = Meteor.subscribe("contacts");
return {
ready: handle.ready()
};
}
render() {
const { ready } = this.data;
}
相关文章:
- Meteor如何接收HTTP请求
- Meteor-将选定窗体中的对象添加到集合中
- 如何使用铁流星与流星的默认路线
- Meteor上的启动页面
- 在流星上使用微信js-sdk时出现拒绝权限错误
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- Meteor-添加用户自定义字段的方法不起作用
- Meteor忘记了密码的实现
- 链接所有<a>Meteor
- 反应性使用“;inProgress团队/反应原生流星“;Meteor 1.3中
- 角流星不适用于meteor 1.3更新
- 流星写入文件 meteor.com
- 流星_wrapAsync已重命名为Meteor.wrapAsyncundefined
- 当使用MUP(流星)部署时,Meteor.js i18n包无法工作
- 流星-我为什么要用这个.userId优于Meteor.userId()
- 为什么流星更新记录而不运行"Meteor.call"更新
- 流星:这个.userId和Meteor.userId()在Meteor方法中都是空的
- 可以用node而不是Meteor来启动流星应用
- 流星.使用Meteor.Mandrill时,wrapAsync没有返回任何值
- 流星.call (Meteor.methods)似乎同时在客户端和服务器上运行——这会导致问题