rethinkdb和totaljs将所有元素都放在前面

时间:2017-12-14 11:34:17

标签: database rethinkdb

我正在尝试将我的数据库的所有元素放在前面并绘制它们。我正在使用totaljs。但我有下一个错误:“无法识别的全局可选参数0: r.table( “属性”)“

定义/ database.js

var r = require('rethinkdb');
var connection = null;

r.connect({
  host: F.config.db_host,
  port: U.parseInt(F.config.db_port)
}, function(err, conn) {
  connection = conn;
  if (err)  throw err;
  r.db('test').tableList().run(conn, (err, res) => {
    if (res.length > 0)  return
     else {
      r.db('test').tableCreate('myNewTable').run(conn, function(err, res) {
      });
    }
  })
});

F.db = {
  insert: (table, data, callback) => {
    r.table(table).insert(data).run(connection, callback);
  },
  get: (table, data, callback) => {
    r.table(table).get(data).run(connection, callback);
  },
  getByIndex: (table, data, callback) => {
    console.log('table', table);
    console.log('data', data);
    r.table(table).getAll(data, {'index': index}).run(connection, (err, res) => {
      if (err) throw err;
      res.toArray(err, res => {
          callback(err, res);
      });
    });
  },
  all: (table, callback) => {
     r.table(table).run(connection, callback);
  }
};

控制器/ index.js

exports.install = function() {
    F.route('/myroute', view_all);      
};

function view_all(){
  let self = this;
    MODEL('myModel').all('myTable', (err, res) => {
        if (err) throw err
        self.view('properties');
    });
}

模型/ myModel.js

exports.table = 'myTable';

exports.schema = (data) => {
  data = data || {};
  var schema = {};
  schema.id = data.id || U.GUID();
  schema.name = data.name || '';
  schema.created = data.created || new Date();
  schema.url = data.url || '';
  schema.description = data.description || '';
  return schema;
};



exports.all = (data, callback) => {
  F.db.all(exports.table, data, callback);
};

视图/ index.html中

<div class="container-fluid">
  <div class="row">
    <div class="col-md-12">
      <div class="project mb-3">
        <div class="project-body border border-grey rounded-0">
            <div class="row no-gutters">
              <div class="col-md-9">
                <div class="row">
                  <div class="col-md-12">
                    <span>@(All elements)</span>
                    @{if model.length > 0}
                    @{foreach m in model}
                    <ul class="all-content-wrapper">
                    </ul>
                  </div>
                  @{end}
                  @{else}
                  <div class="nothing">
                    @(There is no elemetns yet)
                  </div>
                  @{fi}
                  <div class="col-md-12">
                    <div class="project-details">
                      <div class="row align-items-center">
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
        </div>
      </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

需要将模型也传递给视图

function view_all(){
  let self = this;
    MODEL('myModel').all('myTable', (err, res) => {
        if (err) throw err
        self.view('properties', res);
    });