小编leo*_*tes的帖子

Sequelize hasMany加入协会

我正在扩展我的应用程序,我需要加入我之前用Sequelize创建的两个模型,它们如下:

膳食

sequelize.define('meal', {
    mealId: {
        type: DataTypes.INTEGER, 
        primaryKey: true,
        autoIncrement: true
    },
    quantity: {
        type: DataTypes.DECIMAL,
        allowNull: false
    },
    period: {
        type: DataTypes.INTEGER,
        allowNull: false
    }
})
Run Code Online (Sandbox Code Playgroud)

餐饮

sequelize.define('food', {
    idFood: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    nameFood: {
        type: DataTypes.STRING,
        allowNull: false
    }
})
Run Code Online (Sandbox Code Playgroud)

我添加了以下关系:

db.food.hasMany(db.meal, {as : 'Food', foreignKey : 'idFood'});
Run Code Online (Sandbox Code Playgroud)

这一行在Meal上添加了一个idFood列

赶紧解释到底是怎么回事,粮食是许多食品(废话),如面包,大米,豆类等表膳食是识别哪些食物用户与他们的信息选择了一个表.

因此,我的理解是,Meal有很多食物(正如我之前添加的那样)但是Food并不需要与Meal有任何关系,因为它只保存数据并且在我第一次填充之后没有改变.但当我试图加入他们时:

db.meal.findAll({ include : [db.food] }).then(function (meals) {
    console.log(JSON.stringify(meals));
}); …
Run Code Online (Sandbox Code Playgroud)

sqlite join relationships node.js sequelize.js

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

在父级顶部叠加div,大小相同

当我的拖放事件开始时,我需要覆盖一个子div来覆盖它的父div,但我无法使用z-index将子div放在父级之上.

这是我的HTML:

<div class="some-element">
  <div class="parent-div">
    <div class="child-div">
      <p>This should be over the parent</p>
    </div>
    <h1>Some text lorem ipsum</h1>
  </div>

  <div class="another-div">
    <p>lorem ipsum</p>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的CSS

html, body {
  height: 100%;
  width: 100%;
}

.some-element {
  background-color: blue;
  width: 100%;
}

.parent-div {
  background-color: red;
  height: 100%;
  position: relative;
  width: 100%;
  z-index: 1;
}

.child-div {
  background-color: green;
  height: 100%;
  position: relative;
  width: 100%;
  z-index: 999;
}
Run Code Online (Sandbox Code Playgroud)

这是CodePen演示我的问题:https://codepen.io/leofontes/pen/LkgJpo

我认为通过使用z-index和位置相对我可以实现我想要的,但它似乎没有堆叠在父级之上.对于发生了什么有什么想法?

html css overlay position z-index

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

启动SweetAlert以防止用户关闭窗口

我想在关闭窗口之前向用户显示一条消息.我正在使用运行良好的SweetAlert(http://tristanedwards.me/sweetalert).

问题在于JavaScript/jQuery让我知道用户何时尝试关闭窗口/标签然后显示阻止他关闭页面的内容,除非他再次点击.

<script language="JavaScript">
    window.onbeforeunload = confirmExit;
    function confirmExit() {
        swal("Here's a message!");
        return "You have attempted to leave this page. Are you sure?";
    }
</script>
Run Code Online (Sandbox Code Playgroud)

我试过这个,但它在我的SweetAlert上显示了丑陋的常见信息,任何想法?没有返回部分它无论如何关闭窗口,我试过:/

javascript jquery sweetalert

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

只滚动一个部分,而不是整个页面

我正在处理一个项目,其中一个部分通过从数据库请求数据来填充元素,因此其中的元素数量非常可变。

棘手的部分是我们的设计基于不必在页面上滚动的想法,而是在必要时滚动部分。我认为overflow在这些部分使用就足够了,但它并没有给我预期的结果。

我尝试了该overflow属性的所有变体,scroll显示了一个滚动条,但它似乎被冻结了。

如何section-one在不使页面的其余部分可滚动的情况下使其自身可滚动?

我创建了一个带有虚拟版本的代码笔来演示这个问题:http : //codepen.io/leofontes/pen/aNaBox

body {
  overflow: hidden;
}

main {
  margin: 0;
  width: 100%;
  height: 100%;
}

.section-one {
  background-color: #FF0000;
  float: left;
  min-height: 1400px;
  overflow: visible;
  width: 15%;
}

.section-two {
  background-color: #00FF00;
  float: left;
  min-height: 1400px;
  width: 70%;
}

.section-three {
  background-color: #0000FF;
  min-height: 1400px;
  float: left;
  width: 15%;
}
Run Code Online (Sandbox Code Playgroud)
<main>
  <section class="section-one">
    <p>this is section one</p>
    <p>this is section one</p>
    <p>this is section one</p> …
Run Code Online (Sandbox Code Playgroud)

html css overflow

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

Express Passport会话不起作用

我正在构建一个Node应用程序,用户必须在其中注册或登录,然后当他们拖放某些元素(前端都在工作)时,我将其操作及其相应的userId存储在数据库中。

我的理解是,一旦他们注册/登录,我就可以使用req.user来访问其ID并正确存储其操作,但是它不起作用。

这是我的server.js文件中处理Passport的部分。另外,我将Sequelize用作ORM,但是没有req.user部分,所有与数据库打交道的工作都非常完美。

app.use(cookieParser());
app.use(bodyParser.json());

app.use(passport.initialize());
app.use(passport.session());

/****** Passport functions ******/
passport.serializeUser(function (user, done) {
    console.log('serialized');
    done(null, user.idUser);
});

passport.deserializeUser(function (id, done) {
    console.log("start of deserialize");
    db.user.findOne( { where : { idUser : id } } ).success(function (user) {
        console.log("deserialize");
        console.log(user);
        done(null, user);
    }).error(function (err) {
        done(err, null);
    });
});

//Facebook
passport.use(new FacebookStrategy({
    //Information stored on config/auth.js
    clientID: configAuth.facebookAuth.clientID,
    clientSecret: configAuth.facebookAuth.clientSecret,
    callbackURL: configAuth.facebookAuth.callbackURL,
    profileFields: ['id', 'emails', 'displayName', 'name', 'gender'] 

}, function (accessToken, refreshToken, profile, done) {
    //Using next tick to …
Run Code Online (Sandbox Code Playgroud)

session serialization node.js express passport.js

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

无法使用类型为"String"的索引下标[Dictionary <String,Any>]类型的值

我正在尝试读取从Alamofire返回给我的一些数据,但我在尝试导航JSON时遇到此错误.这是我的代码:

Alamofire.request(requestURL).responseJSON { response in
  if let JSON = response.result.value as? [Dictionary<String, Any>] {

      if let reviews = JSON["reviews"] as? [Dictionary<String, Any>] { //Its giving me the error here
          for review in reviews {
              print(review["description"])
          }
      }

  }
}
Run Code Online (Sandbox Code Playgroud)

而我得到的错误:

不能使用类型为'String'的索引下标[Dictionary]类型的值

这是我正在使用的JSON:

{
  "item": {
    "id": 1,
    "name": "The Lord of the Rings: The Fellowship of the Ring",
    "description": "A meek Hobbit from the Shire and eight companions set out on a journey to destroy the powerful One Ring and …
Run Code Online (Sandbox Code Playgroud)

json dictionary swift alamofire swift3

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