作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我在使用 SailsJS 来尝试让 API 真正快速地启动和运行。我还没有设置数据存储(可能会使用 mongodb)但我看到我假设有一个像 SQLite 数据库之类的东西。所以我为用户生成了一个模型和 Controller 。所以在浏览器中我点击了用户/创建。我看到 createdAt 和 updatedAt 但没有 Id。我是否需要真实的数据存储才能查看 ID?这仍然是您免费获得的东西吗?
适配器
// Configure installed adapters
// If you define an attribute in your model definition,
// it will override anything from this global config.
module.exports.adapters = {
// If you leave the adapter config unspecified
// in a model definition, 'default' will be used.
'default': 'disk',
// In-memory adapter for DEVELOPMENT ONLY
// (data is NOT preserved when the server shuts down)
memory: {
module: 'sails-dirty',
inMemory: true
},
// Persistent adapter for DEVELOPMENT ONLY
// (data IS preserved when the server shuts down)
// PLEASE NOTE: disk adapter not compatible with node v0.10.0 currently
// because of limitations in node-dirty
// See https://github.com/felixge/node-dirty/issues/34
disk: {
module: 'sails-dirty',
filePath: './.tmp/dirty.db',
inMemory: false
},
// MySQL is the world's most popular relational database.
// Learn more: http://en.wikipedia.org/wiki/MySQL
mysql: {
module : 'sails-mysql',
host : 'YOUR_MYSQL_SERVER_HOSTNAME_OR_IP_ADDRESS',
user : 'YOUR_MYSQL_USER',
password : 'YOUR_MYSQL_PASSWORD',
database : 'YOUR_MYSQL_DB'
}
};
/*---------------------
:: User
-> model
---------------------*/
module.exports = {
attributes: {
firstName: 'STRING',
lastName: 'STRING'
}
};
最佳答案
做 .../user/findAll
列出所有用户。每个用户都应该有一个“id”属性,例如
{
"username":"admin",
"password":"$2a$10$SP/hWtlJINkMgkAuAc9bxO1iWsvVcglwEU4ctGCiYpx.7ykaFWt56",
"createdAt":"2013-07-12T17:36:29.852Z",
"updatedAt":"2013-07-12T17:36:29.852Z",
"id":1
}
关于sails.js - 在 Sails JS 响应中看不到 Id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17607459/
我是一名优秀的程序员,十分优秀!