小编geo*_*rge的帖子

Sails.js中的唯一属性失败

以下代码表示Sails.js v0.9.4中的帐户模型.

 module.exports = {

      attributes: {
        email: {
          type: 'email',
          unique: true,
          required: true
        },
        password:{
          type: 'string',
          minLength: 6,
          maxLength: 15,
          required:true
        }
      }

    };
Run Code Online (Sandbox Code Playgroud)

当我通过邮递员发送两个POSTS和一个PUT请求到localhost:8080/account时,电子邮件的唯一属性失败.具体来说,我从Postman发送以下HTTP请求:

POST http://localhost:8080/account?email=foo@gmail.com&password=123456  
POST http://localhost:8080/account?email=bar@gmail.com&password=123456    
PUT  http://localhost:8080/account?id=1&email=bar@gmail.com  
GET  http://localhost:8080/account
Run Code Online (Sandbox Code Playgroud)

最后一个GET请求告诉我:

[
  {
    "email": "bar@gmail.com",
    "password": "123456",
    "createdAt": "2013-09-30T18:33:00.415Z",
    "updatedAt": "2013-09-30T18:34:35.349Z",
    "id": 1
  },
  {
    "email": "bar@gmail.com",
    "password": "123456",
    "createdAt": "2013-09-30T18:33:44.402Z",
    "updatedAt": "2013-09-30T18:33:44.402Z",
    "id": 2
  }
]
Run Code Online (Sandbox Code Playgroud)

这会发生吗?
*对于那些不知道的人,Waterline默认生成一个id,它会在每次插入时自动递增.

node.js express sails.js waterline

12
推荐指数
2
解决办法
8014
查看次数

替换div中的文本

我得到了这段代码,我想替换顶层和底层<div>元素之间的"ARRIVAL"文本但我无法找到方法.

我不想用replaceWith,html或类似的方法<div class="left booktext">,因为这将取代HTML元素的其余部分.附加了一个事件处理程序input class="bookfields",我不想丢失它.不幸的是,没有事件授权.

<div class="left booktext">
  ARRIVAL       
  <div class="bookborder">
    <input type="hidden" name="checkin" value="2014-03-05">
    <input type="text" class="bookfields hasDatepicker" style="width:65px;" id="checkin-select" placeholder="dd/mm/yyyy">
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript jquery

2
推荐指数
1
解决办法
1665
查看次数

当Angl中的URL更改时,模板闪烁

我正在开发一个带角度的小应用程序,我很难解决模板闪烁(显示一个模板然后立即显示另一个模板)我面临的问题.

<ng-view>在我的基本模板中定义了一个标记和一些部分文件.

这是我的routeProvider设定:

app.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/', {
        templateUrl: '/static/partials/login.html',
        controller: 'LoginController',
        requireLogin: false
      }).
      when('/login', {
        templateUrl: '/static/partials/login.html',
        controller: 'LoginController',
        requireLogin: false
      }).
      when('/register', {
        templateUrl: '/static/partials/register.html',
        controller: 'RegisterController',
        requireLogin: false
      }).
      when('/profile', {
        templateUrl: '/static/partials/profile.html',
        controller: 'ProfileController',
        requireLogin: true
      }).
      otherwise({
        redirectTo: '/'
      });
}]);
Run Code Online (Sandbox Code Playgroud)

如您所见,我正在定义一个requireLogin属性来检查相应的路由是否要求用户登录到webapp.

以下是我定义的拦截器,它检查是否设置了requireLogin属性,如果是,则询问服务器是否对用户进行了身份验证.如果用户未经过身份验证,则会将其重定向到登录页面.

 app.run(function($rootScope, $location, $http) {
        $rootScope.$on('$routeChangeStart' , function(event, current) {
            if(current.requireLogin) {
              $http.get('/authenticated').success(function(response){
                if(!response.authenticated) {
                  $location.path('/');
                }
              });
            }
         });
    });
Run Code Online (Sandbox Code Playgroud)

当用户未经过身份验证时,会发生闪烁.

javascript angularjs

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

标签 统计

javascript ×2

angularjs ×1

express ×1

html ×1

jquery ×1

node.js ×1

sails.js ×1

waterline ×1