使用 Backbone JS 样板和代码导航
一个新手问题: 我已经从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我真的很希望 Netbeans 的导航器向我展示所有方法:
但我似乎无法让它工作。 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:
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.
我发现这对我来说效果很好:
Backbone 对象包含我的自定义对象,这使我能够轻松导航代码、扩展对象并保存多个文件。
方法如下:
对象 1
对象 2
以及在我的应用程序中:
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
Object 2
and in my app: