小编har*_*rdy的帖子

续集中一张表中同一表的两个外键

我的团队成员模特: -

var teamMember = {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    level: DataTypes.INTEGER,
    supervisorId: {
        type: DataTypes.INTEGER,
        references: {
            model: "employees",
            key: "id"
        }
    },
    employeeId: {
        type: DataTypes.INTEGER,
        unique: true,
        references: {
            model: "employees",
            key: "id"
        }
    }
Run Code Online (Sandbox Code Playgroud)

并且有员工模型

制图: -

db.employee.hasOne(db.teamMember);
db.teamMember.belongsTo(db.employee);
Run Code Online (Sandbox Code Playgroud)

我的查询功能

        db.teamMember.findOne({
        where: { employeeId: req.employee.id },
        include: [db.employee]

    })
    .then(teamMember => {
        if (!teamMember) {
            throw ('no teamMember found');
        }
       consol.log(teamMember)
    })
Run Code Online (Sandbox Code Playgroud)

我的teamMember表就像=

ID ------雇员------ supervisorId

2 ----------- 4 …

node.js sequelize.js

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

在.then函数中发送多个参数

在回调中,我们可以发送任意数量的参数.

同样,我想将多个参数传递给then函数,无论是在Bluebird promises还是本机JavaScript promise中.

像这样:

myPromise.then(a => {
    var b=122;
    // here I want to return multiple arguments
}).then((a,b,c) => {
    // do something with arguments
});
Run Code Online (Sandbox Code Playgroud)

javascript callback promise ecmascript-6 bluebird

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

Google Cloud 抛出错误:无法在 Nodejs 中加载默认凭据

我已将此服务帐户密钥 (my-key.json) 文件存储在我的下载文件夹 (ubuntu) 中,然后将此命令运行到我的控制台中

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/my-key.json"

根据 谷歌云。现在我正在运行此代码,但它引发了我的错误。

const language = require('@google-cloud/language');

const quickstart = async function () {
  // Instantiates a client
  const client = new language.LanguageServiceClient();
 
  // The text to analyze
  const text = 'Hello, world!';
 
  const document = {
    content: text,
    type: 'PLAIN_TEXT',
  };
 
  // Detects the sentiment of the text
  const [result] = await client.analyzeSentiment({document: document});
  const sentiment = result.documentSentiment;
 
  console.log(`Text: ${text}`);
  console.log(`Sentiment score: ${sentiment.score}`);
  console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
}


quickstart();
Run Code Online (Sandbox Code Playgroud)
**ERORR** -
(node:13928) UnhandledPromiseRejectionWarning: …
Run Code Online (Sandbox Code Playgroud)

javascript google-api node.js google-cloud-platform

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

具有动态值的 MenuItem 在 Material UI React 中不起作用

我正在使用 Select,在 React 的 Material UI 中,当我从选择器中选择时,我总是得到未定义的结果。当我们使用价值动态时,这种情况总是MenuItem发生。但如果我使用静态值而不是动态值,它效果很好。但我必须以动态方式与.map运算符一起使用。

请提供在动态值方面效果良好的解决方案。

像这样-> <MenuItem value={SOME-DYNAMIC-VALUE} />

this.state.selectedTagetIdentity = '';

onTargetIdentityChange = (event) => {
  this.setState({ selectedTagetIdentity: event.target.value }); // its undefined always 
}

const splitedIdenties = { 
 'abc1' :[{ id: 12, age: '2' },{ id: 13, age: '3' }], 
 'abc2': [{ id: 14, age: '22' },{ id: 15, age: '25' }] 
};
Run Code Online (Sandbox Code Playgroud)
<Select value={selectedTagetIdentity} onChange={onTargetIdentityChange}>
  {Object.keys(splitedIdenties).map((identityTypeKey, identityTypeIndex) => 
    <div key={identityTypeIndex}>
      <ListSubheader>{identityTypeKey}</ListSubheader>
      {splitedIdenties[identityTypeKey].map(identity => 
        <MenuItem key={identity.id} value={identity.id}>{identity.age}</MenuItem>
        )}
    </div> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs material-ui

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