0

これが私の見解です:

define([
    'jquery',
    'underscore',
    'backbone',
    'models/tableModel',
    'collections/tablesCollection',
    'views/tablesView'
], function($, _, Backbone, tableModel, tablesCollection, tablesView) {
    require(['collections/tablesCollection'], function(tablesCollection) {
        var t = new tablesCollection(null, {url: 'main-contact'});
        var tables = new tablesView({ collection: t, template: 'main-contact-template'});
        tables.url = 'main-contact';
        return tables;  // <!-- returns view, tables can be console.log'ed
    });

    console.log(tables); // <!-- tables is not defined
});

ステートメントtables内を取得して、どこにでもアクセスできるようにするにはどうすればよいですか?これは、ビューを返す必要がある場所のようです。そのため、ルートで使用できます。requireconsole.log

app_router.on('route:index', function(){
        require(['views/tables/mainContactView'], function(mainContactView) {
            console.log(mainContactView);  // <!-- undefined, unless some value is returned from where the console.log() is above
            $('#web-leads').html(mainContactView.render().el);
        });
    });

return 'test'どこに置いたら、ルートに入れるconsole.log(tables)ことができます。console.log()だから私はそこからビューを返す必要があると思います。そのデータを渡すにはどうすればよいですか?今のところ、returnステートメントがあっても、私の見解は未定義です。からビューを取得する必要がありますrequire。それ、どうやったら出来るの?

4

1 に答える 1

0

すでにcollection/tablesCollectiondefineにロードされているので、ロードするために別の操作を行う必要はありませんrequire

ビューの定義は次のように簡単にできます。

define([
    'jquery',
    'underscore',
    'backbone',
    'models/tableModel',
    'collections/tablesCollection',   // You've already required tablesCollection here.
    'views/tablesView'
], function($, _, Backbone, tableModel, tablesCollection, tablesView) {
    var t = new tablesCollection(null, {url: 'main-contact'});
    var tables = new tablesView({ collection: t, template: 'main-contact-template'});
    tables.url = 'main-contact';
    return tables;
});
于 2013-01-30T20:02:41.253 に答える