我开始看看Node.js. 我也在用Express.我有一个问题 - 如何组织Web应用程序路由?所有示例都将所有这些app.get/post/put()处理程序放在app.js中,它运行得很好.这很好,但如果我有一个简单的硬件博客?有可能做这样的事情:
var app = express.createServer();
app.get( '/module-a/*', require('./module-a').urls );
app.get( '/module-b/*', require('./module-b').urls );
Run Code Online (Sandbox Code Playgroud)
和
// file: module-a.js
urls.get('/:id', function(req, res){...}); // <- assuming this is handler for /module-a/1
Run Code Online (Sandbox Code Playgroud)
换句话说 - 我喜欢Django的URLConf,但是在Node.js中.
我正在研究http://gamercity.info/ymusic/.我正在使用UI滑块作为搜索栏.播放视频时,seekTo(seconds)如果用户在搜索栏上的任意位置单击,我想调用一个函数.如何获得seconds点击事件后的新价值?
一个小问题是为什么jQuery会这样做
jQuery.fn = jQuery.prototype = {
init: function() {...},
f1: function() {...},
...
};
jQuery.fn.init.prototype = jQuery.fn;
Run Code Online (Sandbox Code Playgroud)
为什么不简单地添加f1()等init.prototype?它只是美学还是有一些深刻的想法?
普通的Javascript对象可以附加事件吗?说这样的话:
obj = new Object();
obj.addEventListener('doSomething', foo, true);
Run Code Online (Sandbox Code Playgroud)
我知道我可以用jQuery做到这一点,但是没有任何库可以吗?
如果需要,我想在我的.bashrc文件中添加一些内容来运行kinit.有没有办法测试我是否需要做kinit?像这样的东西:
if [ kinitNeeded ];
do kinit;
done
kinitNeeded() { ??? }
Run Code Online (Sandbox Code Playgroud) 这是我的表格(简化的,只有重要的列):
CREATE TABLE things (
id serial primary key
, name varchar
, blueprint json default '{}'
);
Run Code Online (Sandbox Code Playgroud)
以及一些示例数据:
# select * from things;
id | name | blueprint
----+---------+-----------------------------------------------------------------------------
1 | Thing 1 | {}
2 | Thing 2 | {"1":{"name":"Iskapola","wight":"2"}}
3 | Thing 3 | {"1":{"name":"Azamund","weight":"3"}, "2":{"name":"Iskapola","weight":"1"}}
4 | Thing 4 | {"1":{"name":"Ulamir","weight":"1"}, "2":{"name":"Azamund","weight":"1"}}
Run Code Online (Sandbox Code Playgroud)
我想选择键'Azamund'下任意位置的行name。像这样的东西:
# select * from things where * ->> 'name' = 'Azamund';
id | blueprint
----+----------------------------------------------------------------------------
7 | {"1":{"name":"Azamund","weight":"3"}, "2":{"name":"Iskapola","weight":"1"}} …Run Code Online (Sandbox Code Playgroud) 似乎我陷入困境,以便我的发电机不需要参数.所以例如我的生成器代码是这样的:
class MyGenerator < Rails::Generators::NamedBase
source_root File.expand_path('../templates', __FILE__)
def generate_stylesheet
copy_file "my.css", "public/stylesheets/my.css"
end
end
Run Code Online (Sandbox Code Playgroud)
但是当我做rails g my轨道时总是要求额外的争论.你能告诉我怎么这么不需要额外的论证吗?
谢谢.
我想调整jinja.el来使用单行注释##.但我对elisp的了解很糟糕.谁能帮我?我想要什么:我想要hilite
## some text
## {% include "_template.html" %}
Run Code Online (Sandbox Code Playgroud)
作为注释掉的字符串.但它的工作并不完全正确.第一行的片段看起来像是注释而第二 - 不是.这是我得到的:

这里是jinja.el的一部分,取自Jinja的git repo加上我的regexp ##:
(defconst jinja-font-lock-keywords
(list
; (cons (rx "{% comment %}" (submatch (0+ anything))
; "{% endcomment %}") (list 1 font-lock-comment-face))
'("{%-?\\|-?%}\\|{{\\|}}" . font-lock-preprocessor-face)
'("{# ?\\(.*?\\) ?#}" . (1 font-lock-comment-face))
'("## ?\\(.*\\)" . (1 font-lock-comment-face))
'("{#\\|#}" . font-lock-comment-delimiter-face)
'("##" . font-lock-comment-delimiter-face)
;; first word in a block is a command
Run Code Online (Sandbox Code Playgroud) 我想像这样创建JSON:
{
"field1": "value-1",
"field2": "value-2",
"actions": {
"edit": "/edit/action/url"
}
}
Run Code Online (Sandbox Code Playgroud)
使用rabl.它不适用于child方法,也不能用它node- 得到未知的方法错误.那么,是否可以使用rabl模板创建自定义子节点?说这样的话:
collection @datas => :datas
attributes :field1, :field2
child :actions do
node :edit do
edit_datas_path :id
end
end
Run Code Online (Sandbox Code Playgroud)
编辑
我选择这个:
node :actions do
actions = {}
actions[:edit] = edit_customer_group_path(:id)
node :foo do
foos = {}
foos[:bar] = "hello"
foos
end
actions
end
Run Code Online (Sandbox Code Playgroud)
但下面接受的答案也是正确的.