1

Using Durandal widgets, you have to create a folder for each widget, and then 2 files in each folder. For example a mywidget folder containing view.html, model.js files.

This naming style makes it difficult to find files in the solution. Is there any way to name these file names like mywidget.html, mywidget.js?

4

1 回答 1

1

如果您想使用自己的约定,您可以覆盖 Widget 插件相对轻松地加载其部件的方式。例如,如果您希望您的约定是小部件的视图和视图模型都以小部件的种类命名,您可以这样做:

define(["plugins/widget"], function (widget) {
    // Look in 'widgets/[kind]' for '[kind].html' and '[kind].js'
    var convertKindToKind = function (kind) {
        return "widgets/" + kind + "/" + kind;
    };

    widget.convertKindToModulePath = convertKindToKind;
    widget.convertKindToViewPath = convertKindToKind;
});

或者,您可以将该mapKind功能用于“一次性”非常规小部件映射:

// Parameters are: Widget kind, viewId, moduleId
widget.mapKind("mywidget",
    "widgets/mywidget/mywidget",
    "widgets/mywidget/mywidget");
于 2014-03-03T01:15:49.003 回答