小编Zac*_*ook的帖子

jQuery Validator,要求任何一个字段

我试图确保用户输入2个字段中的1个,"ExactOrderSize"或"approxOrderSize".

<p>Exact size of your order (# of items)</p>
<input id="ExactOrderSize" type="text" name="ExactOrderSize">

<p>Approximate size of your order</p>
<select id="approxOrderSize"  name="approxOrderSize" >
    <option value="" selected="selected"></option>
    <option value="0">0-35</option>
    <option value="35">35-50</option>
    <option value="50">50-100</option>
</select>
Run Code Online (Sandbox Code Playgroud)

为此,我使用jQuery Validator的帮助.一切都运行良好,除了这个自定义验证规则,似乎什么都不做.

$('#quoteform').validate({
  rules: {
    FirstName: {
      required: true
    },
    LastName: {
      required: true
    },
    approxOrderSize: {
      required: function() {
        if($('#ExactOrderSize').val()=="")
          return true;
        else
          return false;
      }
    },
    DateNeededBy: {
      required: true
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

我的想法是基本上运行一个函数,如果#ExactOrderSize字段没有填写,则#approxOrderSize需要字段.AKA集required = true

到目前为止,我们从StackOverflow答案中发现的问题是,问题在于可能隐藏的两个领域.首次加载页面时,最初都不显示#ExactOrderSize或#approxOrderSize.

他们必须单击这两个按钮之一才能显示该字段: 在此输入图像描述

根据他们选择的按钮,幻灯片动画会显示相应的字段.

"是" - …

validation jquery jquery-validate

7
推荐指数
1
解决办法
1824
查看次数

Axios Promise Handling - 在react-native中获取"可能未处理的Promise Rejection - TypeError:Network request failed"

react-native登录屏幕上的我的应用程序中,我正在努力在输入错误的用户名/密码组合后为用户提供良好的错误消息.要与API交互我正在使用Axios库.但是,当我在catch语句中出现错误时,我收到这个丑陋的错误消息,说我有一个"未处理的承诺拒绝",我不能做诸如设置组件状态或导航到新页面之类的事情.

我看不出我做错了什么,它看起来就像我在文档中看到的那样.

在我的表单提交功能中,我有:

axios.post('http://192.168.1.11:1337/login', {
  email: this.state.username,
  password: this.state.password
}).then(function (response) {

  // This stuff all seems to work great
  console.log("The response we got: ", response);
  if (response.status == 200) {
    console.log("Status code equals 200");
    Actions.homepage();
  }
}).catch(function (err) {

  // Run into big problems when I get an error
  console.log("Got an error logging in, here's the message: ", err);
});
Run Code Online (Sandbox Code Playgroud)

谁能看到我在这里做错了什么?

PS这是我从服务器返回的错误消息,从中记录下来console.log("Got an error logging in, here's the message: ", err); …

javascript android promise react-native axios

7
推荐指数
1
解决办法
6653
查看次数

如果不应该,身份验证返回"401(未授权)"

我第一次设置了身份验证功能,并且在用户登录后得到了一些意想不到的结果.一位同事给了我一个带有工作身份验证的应用程序来模拟我的应用程序,看起来我所做的一切都是正确的.

我在前端使用AngularJS,SailsJS后端框架和PassportJS身份验证中间件.

我的源代码(现在)公开存储...后端API在Github上(API Github),前端代码在这里找到(前端Github)

基本上发生的是用户

  1. 点击登录按钮,触发此功能

    login: function (credentials) {
        return baseAuth.customPOST(credentials, 'login').then(function (user) {
            $log.debug('User logged in: ', user);
            isAuthenticated = true;
            return user;
        });
    },
    
    Run Code Online (Sandbox Code Playgroud)
  2. 该customPOST的控制器逻辑就是这个

    login: function (req, res, next) {
       passport.authenticate('local', function (err, user, info) {
           if (err) { return res.json(err); }
           else if (user) {
               req.logIn(user, function (err) {
                   if (err) { return res.json(err); }
                   return res.json(user);
               });
           } else { return res.json(400, info); }
    
       })(req, res);
    
    },
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在那一步,护照应该做它的事情并登录用户 …

authentication node.js angularjs sails.js passport-local

6
推荐指数
1
解决办法
1758
查看次数

AngularJS应用程序部署到Heroku,无法找到合适的角度动画版本

我正在向Heroku部署AngularJS应用程序但是在控制台中出现此错误:

remote: bower    ECONFLICT Unable to find suitable version for angular-animate
remote: 
remote:  !     Push rejected, failed to compile Node.js app
remote: 
remote: Verifying deploy....
remote: 
remote: !   Push rejected to test-app-12345
Run Code Online (Sandbox Code Playgroud)

问题(当然)似乎与angular-animate依赖性有关.

我正在使用Heroku angularJS buildpack" Yo Angular "并按照他们的4步流程成功部署到Heroku.

我尝试通过更改我的bower.json文件来修复此问题,就像在StackOverflow回答中推荐的那样,希望它能解决我的问题.它没.

在本地,我grunt serve用来启动应用程序,这对我很有用.

bower.json看起来像这样:

{
  "name": "dashboard",
  "version": "0.0.0",
  "main": "index.html",
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components"
  ],
  "dependencies": {
    "jquery": "~2.0",
    "bootstrap": "~3.1.1",
    "angular": "~1.3.15",
    "angular-ui-router": "~0.2",
    "angular-animate": "~1.3.15",
    "angular-resource": "~1.3.15", …
Run Code Online (Sandbox Code Playgroud)

heroku angularjs bower

3
推荐指数
1
解决办法
783
查看次数

有没有办法找到使用Github编写的一行代码的时间?

我在调试平台的关键功能时遇到了一个有趣的情况,并在代码库的相关函数中遇到了这一行:

// This line below is where shit is hitting the fan
Run Code Online (Sandbox Code Playgroud)

查看该行代码是在什么提交中提交到 Github 的,这将非常有帮助,它可能是来自代码库的前一位开发人员,正在处理我所看到的同一问题。了解他们在该提交期间以及周围的其他工作中所做的其他工作将非常有帮助。

我知道我可以转到该特定文件,搜索更新该文件的所有提交,并按提交搜索这些提交,但这需要很长时间。

有没有一种有效的方法使用 Git / Github 来找出一行代码首次提交的时间?

git github

3
推荐指数
1
解决办法
3396
查看次数

在javascript中,''function({})(req,res)''的最后一个括号是什么意思?

我终于在一年后重新开始认真的软件开发并丢失了我的javascript参考书.对不起,如果这是一个愚蠢的问题,但我已经忘记了这个结束括号在javascript中的含义.

这是一些示例代码:

login: function (req, res) {
    example.function('optionA', function (err, user) {
        if (err) return res.send(err);
        return res.send(user);
    })(req, res);
});
Run Code Online (Sandbox Code Playgroud)

是(req,res)令我困惑的是,这究竟是如何起作用的?

提前致谢.现在感觉不像阿尔伯特爱因斯坦!

javascript callback node.js

0
推荐指数
1
解决办法
62
查看次数

Prerender.io 问题 - 对所有内容都错过了“301”,然后是 404 - Nginx + AngularJS

我正在努力使我的 AngularJS 电子商务应用程序对 SEO 更友好,所以我正在努力让 Prerender.io 在应用程序上运行。

我的托管/服务文件设置是使用来自 AWS 上托管的 docker 容器的nginx

到目前为止,我已经:

  1. 更改了我的 nginx.conf -基于 Prerender 文档推荐的官方 nginx.conf

    server {
        listen 9001;
        server_name localhost;
        root /app;
        index index.html;
    
        location /store {  
            proxy_set_header X-Prerender-Token RIDE(H9j9jdeRANDOMtoken;
    
            set $prerender 0;
            if ($http_user_agent ~* "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
                set $prerender 1;
            }
            if ($args ~ "_escaped_fragment_") {
                set $prerender 1;
            }
            if ($http_user_agent ~ "Prerender") {
                set $prerender 0;
            }
            if ($uri ~* "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff|svg|eot)") {
                set $prerender 0;
            }
    
            #resolve …
    Run Code Online (Sandbox Code Playgroud)

nginx prerender angularjs single-page-application

0
推荐指数
1
解决办法
1042
查看次数