0

初期化時に ExpressJS サーバーから XML を取得するクライアント側のバックボーン モデルを作成するのが困難です。バックボーン モデルが作成されると、初期化関数が呼び出さmodel.fetch()れ、そのモデル ID がクエリ文字列に渡されます。サーバーは ID を読み取り、正しい XML を返す必要があります。

これは現在機能していません (以下のコード)。ブラウザでデバッグすると、ネットワーク リクエストが正しいように見えます/biomodels?id=BIOMD0000000001

ただし、ブラウザ (Chrome) を使用してアクセスすると/biomodels?id=BIOMD0000000001、モデルが正しく取得されます。

Express サーバー ルート ハンドラ:

/*global exports require*/
exports.getModel = function (req, res) {
    // Dependencies
    var biomodels = require('biomodels').BioModelsWSClient;
    // Get SBML From ID
    console.log('requested ID: ' + req.query.id)
    console.log(biomodels.getModelSBMLById(req.query.id, function (err, results) {
        console.log(err + results);
        res.send(err + results);
    }));
};

バックボーン モデル:

define([
    'underscore',
    'backbone'
], function (_, Backbone) {
    'use strict';

    var BioModel = Backbone.Model.extend({
        defaults: {
            sbml: 'was not fetched',
            id: 'was not assigned'
        },

        initialize: function () {
            var modelId = this.id,
                modelSbml = this.sbml;
            this.fetch({
                data: {
                    id: modelId
                },
                type: 'GET',
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log('error in GET: ' + textStatus + errorThrown);
                },
                url: 'biomodels',
                success: function (data, textStatus, jqXHR) {
                    modelSbml = data;
                    console.log('loaded ' + modelSbml);
                }
            });
        }
    });

    return BioModel;
});
4

0 に答える 0