Javascript requirejs如何访问所需对象

Javascript requirejs如何访问所需对象,javascript,requirejs,Javascript,Requirejs,我有: 但它告诉我配置是未定义的 如何访问配置文件 配置: define(['jquery', 'kendo', 'util/addMenu', 'config'], function ($, kendo, addMenu, config) { var obj = { paymentTermsFilterUI: function (e) { e.kendoDropDownList({ dataSource: config.filte

我有:

但它告诉我配置是未定义的

如何访问配置文件

配置:

define(['jquery', 'kendo', 'util/addMenu', 'config'], function ($, kendo, addMenu, config) {
var obj = {
    paymentTermsFilterUI: function (e) {
            e.kendoDropDownList({
                dataSource: config.filters.paymentterms,
                optionLabel: "Select payment term",
                dataTextField: "text",
                dataValueField: "id",
                change: function (e) {
                    obj.setInternalFilter('termId', 'eq', this.value())
                }
            });
        },
}
module.config在require配置中需要相应的config节。由于没有,module.config返回undefined,这将成为config模块的值

简而言之,代码应该是:

require.config({
    baseUrl: '/laravel/public/js/app',
    paths: {
        jquery: '/laravel/public/js/jquery/jquery',
        bootstrap: '../bootstrap/bootstrap.min',
        kendo: '../kendo/kendo.all.min',
        kendo_culture: '../kendo/kendo-culture-en-GB',
        typeahead: '../typeahead',
        text: '../text',
        handlebars: '../handlebars/handlebars',
        io: 'http://view.euautomation.com:8008/socket.io/socket.io'
    },
    shim: {
        "bootstrap": {
            deps: ["jquery"]
        },
        "kendo": {
            deps: ["jquery"]
        },
        "kendo_culture": {
            deps: ["kendo"],
            exports: 'kendo'
        },
        "typeahead": {
            deps: ["jquery"]
        }
    },
    filters: {
        conditions: [
            {"id": 1, "condition": "New"},
            {"id": 4, "condition": "New - FS"},
            {"id": 6, "condition": "New in box"},
            {"id": 5, "condition": "Refurbished"}
        ],
        leadtimes: [
            {"id": 1, "name": "Not set"},
            {"id": 2, "name": "Same day"},
            {"id": 3, "name": "Next day"},
            {"id": 4, "name": "2-3 days"},
            {"id": 5, "name": "3-5 days"},
            {"id": 6, "name": "5-7 days"},
            {"id": 7, "name": "7-10 days"},
            {"id": 8, "name": "3-4 weeks"},
            {"id": 9, "name": "5-6 weeks"},
            {"id": 10, "name": "9 weeks"},
            {"id": 11, "name": "10-14 days"},
            {"id": 12, "name": "7-8 weeks"},
            {"id": 13, "name": "2-3 weeks"},
            {"id": 14, "name": "48 hours"},
            {"id": 15, "name": "10-12 weeks"}
        ],
        warranties: [
            {"id": 1, "warranty": "None"},
            {"id": 2, "warranty": "1 Month"},
            {"id": 3, "warranty": "3 Months"},
            {"id": 4, "warranty": "6 Months"},
            {"id": 5, "warranty": "12 Months"},
            {"id": 6, "warranty": "Lifetime"},
            {"id": 7, "warranty": "24 Months"},
            {"id": 8, "warranty": "DOA"},
            {"id": 9, "warranty": "14 days"}
        ],
        paymentterms: [
            {"id": 1, "text": "Advance"},
            {
                "id": 2,
                "text": "Account 14"
            },
            {
                "id": 3,
                "text": "Account 30"
            },
            {
                "id": 4,
                "text": "Account 60"
            },
            {
                "id": 5,
                "text": "Not set"
            },
            {
                "id": 6,
                "text": "Account 7"
            },
            {
                "id": 7,
                "text": "Account 45"
            },
            {
                "id": 8,
                "text": "Account 10"
            }
        ]
    }
});

define('config', function (require) {
    'use strict';

    var module = require('module');

    return module.config ? module.config() : {};
});
参考资料

通过上述设置,代码:

require.config({
    // other staff as before
    config: { // per module configuration root
        'config': { // this is the configuration of the `config` module
            // configuration staff; may even be empty
            xxx: 5 // example
        }
    }
});
…将输出5。但您将其用作config.filters.paymentterms。可以从简单的配置中进行配置吗

require(['config'], function(config) {
    console.log(config.xxx);
});