小编Tro*_*dol的帖子

节点JS,快速结构和需要混淆

这让我发疯了.我是NodeJS的新手.到目前为止,我喜欢它,但有些事情让我失望.我向一个节点项目提出了一个非常基本的起点,我不确定如何搜索谷歌这个.

//myapp/server.js

var config  = require('./config');
var app     = express();
var api     = require('./app/routes/api')(app, express); // <-- this?

app.use('/', api);

var server = app.listen(3000, function () {
    console.log('\n============================');
    console.log(' Server Running on Port 3000  ');
    console.log('============================\n');
});
Run Code Online (Sandbox Code Playgroud)

然后是包含路由的api.js文件.

//myapp/app/routes/api.js

var config   = require('../../config');
var mysql    = require('mysql');

module.exports = function(app, express) {

    var api = express.Router();

    api.all('/', function(req, res) {...});

    api.all('/route-two', function(req, res) {...});

    api.all('/another-route', function(req, res) {...});

    return api;
}
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想将这里发生的事情分解为一个更有组织的结构,但是,我想了解我正在做的事情.

令我困惑的主要是这条线

var api = require('./app/routes/api')(app, express);
Run Code Online (Sandbox Code Playgroud)

我没有意识到你可以在()() …

javascript node.js express

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

ExtJS 6 Rest Proxy,其中JSON数据对象是ID

我希望有人可以指导我如何处理这个json数据结构.

这是一个例子:(我无法控制这些数据)

{
    "1": {
        "name": "thing 01",
        "attributes": {
            "color": "red",
            "brand": "ACME"
        } 
    },
    "2": {
        "name": "thing 02",
        "attributes": {
            "color": "blue",
            "brand": "ACME"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

所以我对如何使用它获取记录感到困惑 reader

Ext.define('MyApp.model.Thing', {
    extend: 'Ext.data.Model'

    fields: [
        { name: 'name' },
        { name: 'attributes', type: 'auto' }
    ],

    proxy: {
        type: 'rest',
        url: 'http://example.com/api/things',

        reader: {
            type: 'json',
            rootProperty: ??? // <--- How should this work?
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

我想知道是否有办法做某事......

rootProperty: '[id]'
Run Code Online (Sandbox Code Playgroud)

还有一种方法可以在数据对象时指定ID吗?也许以某种方式使用idProperty模型上的配置?

我应该使用reader.format方法吗?那看起来有点粗......

任何想法都是贬值的.谢谢!

api rest json extjs extjs6

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

标签 统计

api ×1

express ×1

extjs ×1

extjs6 ×1

javascript ×1

json ×1

node.js ×1

rest ×1