0

I am using this Neo4J library and I would like to use promises instead. So I tried using bluebird's promisify. I created the following code...

    var db = new neo4j.GraphDatabase('....'),
        Promise = require('bluebird'),
        Cypher = Promise.promisify(db.cypher);

    var query = [
        'MATCH (node)',
        'OPTIONAL MATCH (node)-[rel]->( )',
        'RETURN DISTINCT node as node, collect(rel) as links'
    ].join('\n');

    var i = 0
    var onSuccess = function (results) {
            res.json(parseGraphResponse(results));
        },
        onFail = function (err) {
            console.log("Error " + err);
        };
    Cypher({
        query: query
    }).then(onSuccess).catch(onFail);

However, now I get the following error that is captured onError...

TypeError: Object # has no method 'http'

This version works fine...

    db.cypher({
        query: query
    }, function (err, results) {
        if (err) {
            console.log("Error " + err);
            return;
        }
        res.json(parseGraphResponse(results));
    });

A little more investigation shows that it is blowing up on this code...

GraphDatabase.prototype.cypher = function(opts, cb, _tx) {
  ...
  // Blows up here....
  return this.http({
        method: method,
        path: path,
        headers: headers,
        body: body,
        raw: true
      }, (function(_this) {
        return function(err, resp) {
          ...
        }
      })
}

Laravel 5 CMS making?

I'm trying to build a simple CMS with Laravel 5 and I'm stopped at this:

Category forums duplicating

Category titles are ok, but inside same (dublicating forums)? Why is it? My code:

@extends('layouts.main')
@section('content')
@foreach($categories as $category)
<div class="panel panel-default">
  <div class="panel-heading">{{ $category->title }}</div>
  <div class="panel-body">
      <table class="table">
      <tbody>
      @foreach($forums as $forum)
      <tr>
          <th scope="row">{{ $forum->id }}</th>
          <td><a href="{{ generateForumURL($forum->seo_name, $forum->id) }}">{{ $forum->name }}</a></td>
          <td>{{ $forum->topics }}</td>
          <td>{{ $forum->posts }}</td>
      </tr>
      @endforeach
    </tbody>
   </table>
  </div>
</div>
@endforeach
@stop

In routes:

Route::get('', function()
{
        $forums = DB::table('forums')
                ->select()
                ->get();

        $categories = DB::table('categories')
                ->select()
                ->get();

    return View::make('home', compact('forums', 'categories'));
});

In PhpMyAdmin:

categories: categories table

forums: forums table

I know that I didn't do something, but I don't know what, I'm a newbie with Laravel. P.S I'm not good in english, sorry for my bad language :) Thanks so much in advance ;)

Shortly: I wan't to show the forum in that category which is written in in_category row. Thanks.

4

2 回答 2

1

我打赌这会解决它:

Cypher = Promise.promisify(db.cypher.bind(db));

为了将来参考,调试的方法是将错误消息解释为this没有http方法,但你知道db有,所以this不能设置为db. 事实上,传递db.cypher失去了thisdb.

于 2015-08-04T20:19:14.480 回答
0

除了答案,我建议添加以下内容......

if(db.cypher)
  Promise.promisify(db.cypher.bind(db));

如果数据库关闭, if 将防止失败。就我而言,当我无法访问服务器时,我使用 XML 文件来模拟数据。

于 2015-08-06T14:44:43.013 回答