简体   繁体   English

流星JavaScript-错误处理

[英]Meteor JavaScript - Error Handling

In an HTML form, I have an input field. 在HTML表单中,我有一个输入字段。 I need the value of the input to be what I decide it to be. 我需要输入的值是我决定的值。 Eg I want the value to be only "abc". 例如,我希望该值仅为“ abc”。 If the user writes anything else in the field, then he/she should get an alert/warning/pop-up from the server . 如果用户在字段中写入任何东西,那么他/她应该得到一个警报/警告/ 从服务器上弹出。 How can I code this in Meteor's JavaScript? 如何在Meteor的JavaScript中进行编码

Use Meteor method calls: http://docs.meteor.com/#/full/meteor_methods 使用流星方法调用: http : //docs.meteor.com/#/full/meteor_methods

On the server side: 在服务器端:

Meteor.methods({
  "is-secret-valid": function (secret) {
    return {
      isValid: (secret === "123")
    }
  },
});

And on the client side: 在客户端:

myFunc() {
  let secret = ... // get input field from UI
  Meteor.call("is-secret-valid", secret, (error, result) => {
    if (error) {
      // Meteor failed to call, handle error
      return;
    }
    let isValid = result.isValid; 
    {...}
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM