Javascript 与Meteor和React的双向数据绑定

Javascript 与Meteor和React的双向数据绑定,javascript,meteor,reactjs,Javascript,Meteor,Reactjs,所以Meteor使用getMeteorData()而不是getInitialState()那么我们如何进行绑定呢?考虑到此用户配置文件的姓氏: ... getMeteorData() { return { u = Meteor.user() } }, componentRender() { let instance = this; // there is no way you can have two-way binding here. She types in "Brow

所以Meteor使用
getMeteorData()
而不是
getInitialState()
那么我们如何进行绑定呢?考虑到此用户配置文件的姓氏:

...

getMeteorData() {
 return {
   u = Meteor.user()
 }
},

componentRender() {
  let instance = this;
  // there is no way you can have two-way binding here. She types in "Brown".
  return(<div><input value={instance.data.user.profile.surname }</div>)
},

render() {
 return(<div>{this.data.user ?  this.componentRender() : <p>Loading...</p>}</div>)
}

...
。。。
getMeteorData(){
返回{
u=Meteor.user()
}
},
componentRender(){
让实例=这个;
//这里不可能有双向装订。她输入“棕色”。

return(Meteor默认情况下不会提供自动双向绑定

您需要为输入添加一个on change事件处理程序,以处理用户名中的更新

在onChanged中,您可以拨打电话更新用户的姓氏

Meteor.users.update ...
请不要认为这根本没有效率,因为每次用户更改输入时都会调用更新。最好有一个按钮单击以触发更新事件


请参阅:

是的,但还有更多。我已经有了
Meteor.users.update
。我希望对输入字段进行绑定。因为
值设置了,所以当您尝试键入时,它不会更改。您自己试试看。我唯一解决我问题的方法是: