小编sgr*_*454的帖子

如何将文字与图标字体垂直对齐?

我有一个非常基本的HTML混合纯文本和图标字体:

<div class="ui menu">
    <a href="t" class="item"><i class="large home basic icon"></i><span class="nav-text"> Accueil</span></a>
    <a href="" class="item"><i class="large camera retro icon"></i><span class="nav-text"> Créations</span></a>
    <a class="item"><span class="nav-text">Qui-suis je </span><i class="large help basic icon"></i></a>
</div>
Run Code Online (Sandbox Code Playgroud)

问题是图标没有完全呈现在与文本相同的高度:

在此输入图像描述

有什么建议可以解决吗?

html css fonts font-awesome

54
推荐指数
6
解决办法
9万
查看次数

从其他配置文件访问配置变量

我在配置文件中使用另一个配置文件中的config var设置时遇到问题.例如

// file - config/local.js
module.exports = {
  mongo_db : {
    username : 'TheUsername',
    password : 'ThePassword',
    database : 'TheDatabase'
  }
}

// file - config/connections.js
module.exports.connections = {
  mongo_db: {
    adapter: 'sails-mongo',
    host: 'localhost',
    port: 27017,
    user: sails.config.mongo_db.username,
    password: sails.config.mongo_db.password,
    database: sails.config.mongo_db.database
  },
}
Run Code Online (Sandbox Code Playgroud)

当我'航行升降机'时,我收到以下错误:

user: sails.config.mongo_db.username,
      ^
ReferenceError: sails is not defined
Run Code Online (Sandbox Code Playgroud)

我可以在其他地方访问配置变量 - 例如,这有效:

// file - config/bootstrap.js
module.exports.bootstrap = function(cb) {
  console.log('Dumping config: ', sails.config);
  cb();
}
Run Code Online (Sandbox Code Playgroud)

这会将所有配置设置转储到控制台 - 我甚至可以在那里看到mongo_db的配置设置!

我很困惑.

sails.js

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

在$ q.reject上没有调用$ routeChangeError


我有一个带有Sails JS后端的Angular JS应用程序,并且在路径内(在app.js中)我有:

.state('app.detail', {
  url: "/detail",
  views: {
    'menuContent' :{
      templateUrl: "templates/detail.html",
      controller: 'UserUpdateCtrl',
      resolve: {
        auth: ["$q", "userData", function($q, userData) {
          var userInfo = userData.getUserInfo();
          if (userInfo) {
            return $q.when(userInfo);
          } else {
            return $q.reject({ authenticated: false });
          }
        }]
      },
    }
  }
})
Run Code Online (Sandbox Code Playgroud)

(这是遵循本指南)

现在在同一个文件中,我有$ routeChangeError:

.run(function($rootScope) {
  $rootScope.$on("$routeChangeError", function(event, current, previous, eventObj) {
    if (eventObj.authenticated === false) {
      $location.path("/login");
    }
  });
Run Code Online (Sandbox Code Playgroud)

在chrome上调试时,我看到函数已定义,但未调用.
我在这里错过了什么?

javascript angularjs angular-routing sails.js

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

将自定义Express中间件(如jQuery-File-Upload)添加到Sails.js

我仍然难以理解如何向sails.js添加中间件.我听说过使用policies.js,创建自定义策略,添加到local.js等.所以有人可以告诉我如何将jquery-file-upload-middleware添加到sails 应用程序中.提前致谢

node.js sails.js

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

水线协会,改变外键?

最新的水线现在支持协会.这是一对多的例子

// A user may have many pets
var User = Waterline.Collection.extend({

  identity: 'user',
  connection: 'local-postgresql',

  attributes: {
    firstName: 'string',
    lastName: 'string',

    // Add a reference to Pets
    pets: {
      collection: 'pet',
      via: 'owner'
    }
  }
});

var Pet = Waterline.Collection.extend({

  identity: 'pet',
  connection: 'local-postgresql',

  attributes: {
    breed: 'string',
    type: 'string',
    name: 'string',

    // Add a reference to User
    owner: {
      model: 'user'
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

这会owner在宠物集合上创建一个字段.除了使用现有数据库之外,这没什么问题.它称之为外键owner_id.

无论如何都要覆盖数据库中使用的字段名称?

foreign-keys associations sails.js waterline

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

水线,尝试创建一对多关联时出错

我有这些模型:

// Material.js

module.exports = {
attributes: {

    name: {
        type: 'string',
        required: true
    },
    source_info: {
        type: 'string',
        required: true
    },
    category: { model: 'category_mat' }
}
};
Run Code Online (Sandbox Code Playgroud)

和:

// Category_Mat.js

module.exports = {
attributes: {
    name: {
      type: 'string',
      required: true
    },
    material:{
        collection: 'material',
        via: 'category'
    }
},
};
Run Code Online (Sandbox Code Playgroud)

但是当我运行应用程序时,我收到此错误:

/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:82
throw new Error('Trying to access a collection ' + collection + ' that is 
      ^

Error: Trying to access a collection category_mat that is not defined. …
Run Code Online (Sandbox Code Playgroud)

sails.js waterline

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

Sails.js中的错误处理

我刚开始使用Sails.js,这是一个了不起的框架.但我遇到了一些情况,我找不到谷歌的解决方案,所以我来到这里寻求帮助.

我有一个控制器连接到另一个远程服务,使用非常旧设计的API,充满XML响应和不一致性,将该服务包装在简单干净的API中.所以我有一些路由器,如:

list: function(req, res) {
    params = {
        ...
    }

    FooService.request(data, function(error, response) {
        res.send(response)
    })

    process.once('uncaughtException', function(err) {
        res.send(500, '[Foo] ' + err);
    });
},
Run Code Online (Sandbox Code Playgroud)

'process.once'用于异步异常,可能在FooService.request进程中引发.我知道这是不好的代码,我的问题是:如何处理这种情况更多的Sails.js方式?

在Node.js中,我们有Domainconnect-domain,它们是针对这些问题而设计的.因为Sails.js基本上是Express,它可以很好地促进连接域,我认为可能有一些惯用的方法来做到这一点.

我试过在config/local.js中添加这个:

module.exports = {
    ...
    express: {
        customMiddleware: function(app) {
            console.log('Custom middleware config called')

            var domain = require('connect-domain')
            app.use(domain())
            .use(function(err, req, res, next) {
                console.log('Error catched!')
                res.send(500, '[Foo] ' + err)
            })
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

当发生未捕获的异常时,它不会崩溃服务器并且错误500被返回到客户端('app.use(domain())'工作).但是没有调用自定义错误处理程序.不知道为什么.

sails.js

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

如何在OpenShift上的Sails.js中启用CORS

我正在尝试在SailsJS v0.9.15中启用CORS ...如果我在cors.js中设置"allRoutes:true",它仍无法解决,我仍然会收到与CORS相关的错误.为什么这不起作用?根据这个,它应该足够了... https://github.com/balderdashy/sails-docs/blob/master/todo/config.cors.md

Firefox中的错误:"跨源请求被阻止:同源策略不允许在www.domain.com上读取远程资源.这可以通过将资源移动到同一域或启用CORS来修复."

误差在铬:"在'访问控制允许来源’报头包含无效值'空’产地'www.domain.com’因此不允许访问."

这是一个错误吗?

Sails.js(REST api)托管在Openshift上,这可能是个问题吗?

感谢帮助...

node.js cors openshift sails.js

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

高频呼叫导致在Waterline&Sails中使用findOrCreate重复

如何在Postgresql数据库的Sails中使用Waterline处理高频updateOrCreate请求?

我尝试使用findOrCreate然后更新项目,我尝试了findOne然后更新或创建项目,我试图放置一个beforeCreate,一个beforeValidation钩子方法来检查项目是否存在但没有任何成功.我是否应该添加错误处理程序以从唯一索引中获取错误并再试一次?

Waterline文档中,有一个警告,但没有解决这个问题的方向.

谢谢你的任何提示.

postgresql sails.js waterline

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

我对Sails.js水线一对一关联逻辑感到困惑

所以我之所以感到困惑,是因为我是一名PHP开发人员并且使用过很多Laravel和FuelPHP

我真正理解的是它自己的关联.

我的意思是,我想创建一个基本的hasOne/BelongsTo逻辑,具体如下

用户有一个个人资料

个人资料属于用户

我习惯了下面的建立(Laravel风格)

用户表

id | username    | email     | password 
---------------------------------------
1  | My Username | My email  | 1234568
Run Code Online (Sandbox Code Playgroud)

Users_profile表

user_id | first_name    | last_name      
----------------------------------------
1       | My First name | My Last name  
Run Code Online (Sandbox Code Playgroud)

然后我就这样定义了模型

用户模型

class Users extends Eloquent 
{
    public function profile() 
    {
        return $this->hasOne('profile');
    }
}
Run Code Online (Sandbox Code Playgroud)

档案模型

class Profile extends Eloquent 
{
    protected $tableName = 'users_profile';

    protected $primaryKey = 'user_id';

    public function user() 
    {
        return $this->belongsTo('User');
    }
}
Run Code Online (Sandbox Code Playgroud)

它只是工作,因为return $this->hasOne('profile'); …

orm associations node.js sails.js waterline

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