Meteor节点 - 简单模式allowedValues /自定义函数

时间:2018-04-16 19:49:21

标签: meteor database-schema

我试图使用Adeed node-simple-schema这两个字段相互依赖:

const Schemas = {};

Schemas.User= new SimpleSchema({
  name: { type: String },
  surname: { 
    type: String, 
    allowedValues(){
      if ( this.field('name').value === "Daniel" ) {
        return SomeCollection.find().fetch().map(obj => ...)
      }
    }
});

但是this.field内的custom()allowedValues()内的allowedValues无法使用name和其他功能。 我想要的是:让this.field('name').value === "Daniel"取决于用户放在allowedValues字段(custom())中的内容。或者可以在custom(){ ... return allowedValues; // limit what the user can provide to the field. } 内使用SELECT p.ID, count(opened)/x.opened FROM projects p JOIN ( SELECT p.id, count(e.id) as count, avg(opened) as opened, avg(read_email) as clicked, avg(started_video) as started_watching, sum(views) as views FROM projects p INNER JOIN guests g ON g.project_id = p.id INNER JOIN videos v ON v.guest_id = g.id INNER JOIN emails e ON e.video_id=v.id GROUP BY p.id ) x GROUP BY p.id ; 吗?

let currentWindowController = self.view.window?.windowController as! MainWindowViewController
            let childWindowControllers = windowControllers[currentWindowController]
            if let subPreferencesWindowController: SubPreferenceWindowViewController? = {
                for windowController in childWindowControllers! {
                    if windowController is SubPreferenceWindowViewController {
                        return windowController as? SubPreferenceWindowViewController
                    }
                }
                return nil
            }(){
                let subPreferencesController = subPreferencesWindowController?.contentViewController as! SubPreferenceViewController
                subPreferencesController.appStateJSON = self.appStateJSON!
                subPreferencesController.preferences = self.preferencesJSON!
                subPreferencesController.setUpSubPreferences()
            }

注意:我使用UniForms而不是AutoForm

1 个答案:

答案 0 :(得分:0)

我终于使用UniForms在客户端解决了我的问题。 这就是我获得字段值的方式:

<AutoForm 
 schema={ Schemas.User } 
 onChangeModel={ model =>  ( 
   model.name ? this.setState({ name: model.name }) : ''
  )}
 ...
>
...
</Autoform>

使用onChangeModel={ model.name ? this.setState({ name: model.name }) : '' )}我可以在模型更改时随时存储名称的值。 Reference 我想也可以使用findValue。但是我没有尝试过,因为onChangeModel满足了我的需求。