我有两个型号。员工和角色。我正在使用sails-filemaker适配器。 每个工作人员都有一个主要角色,该角色在文件制作者数据库中正确链接。问题是如何在引用员工时显示角色属性。
鉴于
职员:
/**
* Staff.js
*
* @description :: Staff employed by the business
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
connection: 'filemaker',
tableName: 'staff-list-api-layout',
autoPK:false ,
autoCreatedAt: false ,
autoUpdatedAt: false ,
attributes: {
id: {
columnName: 'staff_id_',
type: 'integer',
primaryKey: true,
unique:true
} ,
roleId:{
columnName: 'role_id',
type: 'integer',
foreignKey: true
},
role: {
model: 'role',
unique: true
} ,
name:{
columnName:'full_name',
type: 'string'
},
createdAt:{
type:'date'
},
updatedAt:{
type:'date'
}
}
};
作用:
/**
* Role.js
*
* @description :: Roles that employees can have
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
connection: "filemaker",
tableName: 'roles-api-layout',
autoPK:false ,
autoCreatedAt: false ,
autoUpdatedAt: false ,
attributes: {
id: {
columnName: 'role_id_',
type: 'integer',
primaryKey: true
},
role: {
type: 'string'
},
timesheetSort: {
columnName:'timesheet_sort',
type: 'integer'
},
createdAt: {
type: 'date'
},
updatedAt: {
type: 'date'
}
}
};
,其中
http://192.168.1.71:6366/role/1返回
{
"role": "Artist",
"createdAt": "2016-09-20T07:27:12.000Z",
"updatedAt": "2016-09-20T07:27:22.000Z",
"modid": "5",
"recid": "1",
"id": 1,
"timesheetSort": 1
}
和
http://192.168.1.71:6366/staff/3返回
{
"createdAt": "2016-06-20T08:31:03.000Z",
"updatedAt": "2016-06-20T09:22:49.000Z",
"staff_role::role": "Artist.",
"modid": "15",
"recid": "28",
"id": 3,
"roleId": 1,
"name": "David"
}
我需要在模型中更改什么才能获得
{
"createdAt": "2016-06-20T08:31:03.000Z",
"updatedAt": "2016-06-20T09:22:49.000Z",
"modid": "15",
"recid": "28",
"id": 3,
"roleId": 1,
"role" : {
"role": "Artist",
"createdAt": "2016-09-20T07:27:12.000Z",
"updatedAt": "2016-09-20T07:27:22.000Z",
"modid": "5",
"recid": "1",
"id": 1,
"timesheetSort": 1
} ,
"name": "David"
}
答案 0 :(得分:0)
而是定义"角色"属性在您的员工模型中使用它:
$('#en').click(function(){
$('div[id^=fr], div[id^=de]').hide();
$('#en1, #en2').show();
});
$('#fr').click(function(){
$('div[id^=en], div[id^=de]').hide();
$('#fr1, #fr2').show();
});
$('#de').click(function(){
$('div[id^=fr], div[id^=en]').hide();
$('#de1, #de2').show();
});
您可以查看模块分析