小编leo*_*APA的帖子

ng-repeat在bootstrap模式中不起作用

ng-repeat用来在不同的bootstrap中显示不同的内容(即数组中的项)modal,但是在这个例子中发生了一些奇怪的事情.

我在这里包含'模态' ng-repeat:

<div ng-repeat="item in items">

  <button type="button" class="btn btn-info" data-toggle="modal" data-target="#example">
    {{item}}
  </button>

  <div class="modal" id="example">
    <div class="modal-content">
      {{item}}
    </div>
  </div>

</div>
Run Code Online (Sandbox Code Playgroud)

因此预期的结果应该是具有三个不同内容的三个按钮(例如<button>'hi'应该具有内容hi,hello具有内容hello),但是如在示例中看到的,所有三个按钮具有相同的关联模态内容.

任何建议或意见表示赞赏.

html javascript twitter-bootstrap angularjs angularjs-ng-repeat

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

knex 如何检查当前迁移是否是最新的

我正在使用 knex 进行 postgres 迁移版本控制。基本思想是:每次节点启动时,都会检查当前数据库迁移是否是最新的。如果没有,则通过 申请最新的knex.migrate.latest().then(....)

例如,我有一个init.js迁移文件,它是我当前的数据库版本。然后我提交一份新的newMigration.js并重新启动服务器。我希望节点找到新的迁移并应用它。

我知道有一个.currentVersion函数可以获取当前的db迁移版本,但是node如何知道新添加的迁移(版本)?

请指教!谢谢!

postgresql knex.js

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

如何更新猫鼬中的部分而非全部字段

这是用户架构:

var UserSchema = new Schema({
    username: { type: String, required: true, index:{unique: true} },
    firstName: { type: String, required: true },
    lastName: { type: String, required: true },
    email: { type: String, required: true, index:{unique: true} }, 
    password: { type: String, required: true, select: false }
});
Run Code Online (Sandbox Code Playgroud)

这是 http PUT 请求:

  // update user information
  api.put('/users/:username', function(req, res) {

    User.findOne({username: req.params.username}, function(err, user) {

      if (err){
        res.send(err);
        return;
      }

      if (!user){
        res.status(404).send({
          success: false,
          message: "user not found"
        }); …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb node.js express

3
推荐指数
2
解决办法
9916
查看次数

通过socket.io更新实时d3图表

我正在编写一个基于d3.js的实时图表指令.结构如下所示:

myDirective.js:

app.directive('myDirective', function(socketio) {

  return {
    restrict: 'EA',
    templateUrl: '../../views/partials/chart.html',
    controller: DataController,

    link: function(scope, elem, attrs, ctrl) {

      scope.Watch = scope.$watch(function() {
        return ctrl.data;
      }, function(newVal) {
        // d3 code part
      });

      socketio.on(event, function(newdata) {
        ctrl.data.push(newdata);
        // redraw chart
      });
    }
  };
});
Run Code Online (Sandbox Code Playgroud)

在上面的d3代码部分中,我指的是http://bl.ocks.org/gniemetz/4618602.主要代码几乎相同,图表显示良好.

现在我想使用socket.io通过代码更新图表

socketio.on(event, function(newdata) {
  ctrl.data.push(newdata);
  // redraw chart
});
Run Code Online (Sandbox Code Playgroud)

但不知道如何使用更新的'ctrl.data'有效地重绘图表.我知道在Morris.js中,我们可以通过'.setData(ctrl.data)'方法完成此操作,但不知道如何在d3中更新.任何的想法?

ps:我试图将上面的d3代码复制/粘贴到这个地方,但总有一个错误说:"TypeError:t.slice不是函数"

谢谢,

directive node.js socket.io d3.js angularjs

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

为什么base64编码的字符串的大小比原始文件大

快问,我的原始pdf文件大小约为24MB,但是当我将其编码为基于64字符串时,字符串大小约为31MB,只是想知道为什么?

图像文件很容易理解,因为它可能会失去一些压缩,但它也发生在pdf或其他一些格式文件中?

javascript file

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

如何等待mongoose .exec功能完成?

我是由asychronous nodejs和mongoose共同融合的.简单地说,我想发布一个用户名数组并检查,如果用户名在数据库中,那么我把它放在valid数组中,否则,把它放在invalid数组中.

这是我目前的代码:

var User = require('../../db/models/user');

api.post('/userlist', function(req, res) {

  var invalid = []; // usernames which can not be found in database
  var valid = []; // usernames which can be found in database

  (req.body.userlist).forEach(function(username) {

    User
      .findOne({username: username})
      .exec(function(err, user) {

        if (err) {
          res.send(err);
          return;

        } else if (!user) {

          invalid.push(username);

        } else {

          valid.push(req.params.item);
        }
      });
  });

  res.send({
    Invalid: invalid,
    Valid: valid
  });

});
Run Code Online (Sandbox Code Playgroud)

当我执行上面的代码时,它直接输出初始空数组.

Invalid: [],
Valid: []
Run Code Online (Sandbox Code Playgroud)

我知道那是因为第一次的NodeJS执行该res.send …

javascript mongoose node.js

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