使用 Backbone JS 样板和代码导航

发布于 2025-01-07 10:50:51 字数 1614 浏览 1 评论 0原文

一个新手问题: 我已经从 https://github.com/david0178418/BackboneJS-AMD-Boilerplate 下载了主干样板 它使用 require.js,我想知道开发过程中的代码导航。

这是我的问题: 假设我有 2 个视图,一个视图扩展另一个视图,如下所示:

视图 1:

define([
    'underscoreLoader',
    'backboneLoader',
    'text!templates/main.html'
],
    function (_, Backbone, MainTemplate) {
        "use strict";

        return Backbone.View.extend({
            template:_.template(MainTemplate),

            initialize:function () {
                this.render();
            },

            log:function(msg){
                console.log(msg);
            },

            render:function () {
                this.$el.append(this.template({}));
                return this;
            }
        });
    }
);

视图 2:

define([
    'underscoreLoader',
    'backboneLoader',
    'text!templates/other.html',
    'views/main-view'
],
    function (_, Backbone, MainTemplate,MainView) {
        "use strict";

        // how would you navigate to MainView (main-view.js) 

        return MainView.extend({
            template:_.template(MainTemplate),

            initialize:function () {
                this.render();
            },

            render:function () {
                this.log("my message");
                this.$el.append(this.template({}));
                return this;
            }
        });
    }
);

现在,当我开发(我使用 IntelliJ)时,我想在扩展视图上单击鼠标中键 MainView 并导航到无需浏览项目树即可查看代码。

使用这个样板可以吗?有更好的方法或更好的样板吗?

a newbe question:
I've downloaded the backbone boilerplate from https://github.com/david0178418/BackboneJS-AMD-Boilerplate it uses require.js and I wonder about the code navigation during development.

Here is my question:
let's say I have 2 views one extend the other like so:

View 1:

define([
    'underscoreLoader',
    'backboneLoader',
    'text!templates/main.html'
],
    function (_, Backbone, MainTemplate) {
        "use strict";

        return Backbone.View.extend({
            template:_.template(MainTemplate),

            initialize:function () {
                this.render();
            },

            log:function(msg){
                console.log(msg);
            },

            render:function () {
                this.$el.append(this.template({}));
                return this;
            }
        });
    }
);

View 2:

define([
    'underscoreLoader',
    'backboneLoader',
    'text!templates/other.html',
    'views/main-view'
],
    function (_, Backbone, MainTemplate,MainView) {
        "use strict";

        // how would you navigate to MainView (main-view.js) 

        return MainView.extend({
            template:_.template(MainTemplate),

            initialize:function () {
                this.render();
            },

            render:function () {
                this.log("my message");
                this.$el.append(this.template({}));
                return this;
            }
        });
    }
);

Now when I develop (I use IntelliJ) I would like to middle click MainView on the extended view and navigate to the code without having to browse the project tree.

Is that possible using this boilerplate? is there a better approach or a better boilerplate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鯉魚旗 2025-01-14 10:50:51

我真的很希望 Netbeans 的导航器向我展示所有方法:

var New_Controller = Backbone.View.extend({
    el : null, ...
}

但我似乎无法让它工作。 Google 为 @lends 想出了一些办法,但我什至无法将 Backbone.js 加载到代码提示缓存中。

我最终安装了 WebStorm(我在所有 Egghead.io 教程中看到了 IDE)以使导航器列出所有方法和属性。

仅供参考,Aptana Studio 和 Zend Studio 的表现与 Netbeans 完全不同。而面向 JavaScript Web 开发人员的 Eclipse IDE 仅部分有效(在现实生活中不切实际);它使整个层次结构扁平化。

I would really like Netbeans's navigator to show me all the methods:

var New_Controller = Backbone.View.extend({
    el : null, ...
}

But I can't seem to get it to work. Google came up with something for @lends, but I can't even get Backbone.js to get loaded to the code hint cache.

I ended up installing WebStorm (I saw the IDE in all the egghead.io tutorials) to get the navigator to list all methods and properties.

FYI, Aptana Studio and Zend Studio showed nothing like Netbeans. And Eclipse IDE for JavaScript Web Developers only partially (impractical in real life) works; it flattens the entire hierarchy.

錯遇了你 2025-01-14 10:50:51

我发现这对我来说效果很好:
Backbone 对象包含我的自定义对象,这使我能够轻松导航代码、扩展对象并保存多个文件。

方法如下:

对象 1

function ItemModel() {
    ItemModel.model = (
        Backbone.Model.extend({
            initialize:function () {

            },
            defaults:{
                name:"item name"
            },
            log:function(){
                console.log("inherited method");
            }
        })
        );
    return new ItemModel.model();
}

对象 2

function ItemModel2() {
    ItemModel2.model = (
        ItemModel.model.extend({
            initialize:function () {

            },
            defaults:{
                name:"item name2"
            }
        })
        );
    return new ItemModel2.model();
}

以及在我的应用程序中:

var App = {
    item:new ItemModel(),
    item2:new ItemModel2()
};

I found this to work fine for me:
the Backbone Objects are wrapped with my custom objects, which allows me to navigate code, extend objects and keep multiple files easily.

Here is how:

Object 1

function ItemModel() {
    ItemModel.model = (
        Backbone.Model.extend({
            initialize:function () {

            },
            defaults:{
                name:"item name"
            },
            log:function(){
                console.log("inherited method");
            }
        })
        );
    return new ItemModel.model();
}

Object 2

function ItemModel2() {
    ItemModel2.model = (
        ItemModel.model.extend({
            initialize:function () {

            },
            defaults:{
                name:"item name2"
            }
        })
        );
    return new ItemModel2.model();
}

and in my app:

var App = {
    item:new ItemModel(),
    item2:new ItemModel2()
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文