我正在使用typeahead.js将产品ID分配给隐藏的html表单字段.当匹配时,这很有用:
$('.products_tt .typeahead').typeahead
name: 'products_tt',
prefetch:
url: '/products.json',
ttl: 60 * 5e3
template: '<p><strong>{{value}}</strong> – {{year}}</p>',
engine: Hogan
$('.products_tt .typeahead').on "typeahead:selected typeahead:autocompleted", (e,datum) ->
$('#disk_file_product_id').val(datum.id)
Run Code Online (Sandbox Code Playgroud)
当输入字段留空时,我清除隐藏字段:
$('.products_tt .typeahead').blur ->
if $(this).val().length == 0
$('#disk_file_product_id').val("")
Run Code Online (Sandbox Code Playgroud)
但是我还需要在输入字段中输入文本时清除隐藏字段,但是没有匹配.
我的Java/Coffeescript技能很弱,所以不确定如何做到这一点?!?
我正在尝试添加coffeescripts插件到notepadd ++.我从这里找到了这个插件..dll我从上面的链接下载的zip文件中没有文件.当我读到ReadMeFile时,它说.
# CoffeeScript syntax highlighting for Notepad++
***
Will syntax highlight files with extensions of coffee, coco, and CAKEFILE using Notepad++'s user-defined language(within its limits).

## Deployment
1. If you don't have an userDefineLang.xml file already, you can drop this file among your other configuration file, in the Notepad++ Install Folder. It should be named userDefineLang.xml.
2. Otherwise, open both the existing and new file.
- Select all of the new file, …Run Code Online (Sandbox Code Playgroud) 我正在使用coffeescript.我的代码非常简单:
class SomeCollection extends Backbone.Collection
constructor: (@options) ->
url: ->
"#{$SCRIPT_ROOT}/some/data/#{@options.someId}"
model: SomeModel
class SomeView extends Backbone.View
initialize: ->
myCollection = new SomeCollection()
myCollection.fetch
success: (coll, resp) ->
console.log coll
Run Code Online (Sandbox Code Playgroud)
从我的集合的url返回的JSON正是:
[{"id": 1, "comments": "", "name": "images/exceptions/59.png"}]
但是,在将任何内容打印到控制台之前,我在第768行收到了backbone.js错误:无法读取未定义的属性1.未定义的对象this._byId在集合的get函数中.我怎么解决这个问题?
问题是如何使用turbolinks并且每个页面都有特定的元标记?
这是application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require dashboard
//= require turbolinks
Run Code Online (Sandbox Code Playgroud)
这是应用程序布局视图:
<title><%= yield_or_default(:title) -%></title>
<meta name="description" content="<%= yield_or_default(:meta_desc) -%>">
<meta name="keywords" content="<%= yield_or_default(:meta_keywords) -%>">
<meta name="robots" content="<%= yield_or_default(:robots) -%>">
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
Run Code Online (Sandbox Code Playgroud)
这是仪表板CoffeeScript:
jQuery ->
$("#list_tags").html(list_tags())
list_tags = ->
"Title: \"" + $('title').text() + "\"<br />" +
"Meta Description: \"" + $('meta[name=description]').attr('content') + "\"<br />" +
"Meta Keywords: \"" + …Run Code Online (Sandbox Code Playgroud) 嗨,我不会自己处理上传流而不接触磁盘驱动器.所以,我的自然选择是多方模块.
我拿了一般的例子,根据页面https://npmjs.org/package/multiparty的说明,我将form.parse更改为非回调请求.在这种情况下,不会触及磁盘.
我的代码看起来像这样:
multiparty = require("multiparty")
http = require("http")
util = require("util")
# show a file upload form
http.createServer((req, res) ->
if req.url is "/upload" and req.method is "POST"
form = new multiparty.Form()
form.on 'error', (err) ->
console.log "Error received #{err}"
form.on 'aborted', ->
console.log "Aborted"
form.on 'part', (part) ->
console.log "Part"
form.on 'close', (part) ->
console.log "close received"
res.writeHead 200,
"content-type": "text/plain"
res.end "received upload:\n\n"
form.on 'progress', (bytesReceived, bytesExpected) ->
console.log "Received #{bytesReceived}, #{bytesExpected}"
form.parse req
else …Run Code Online (Sandbox Code Playgroud) 这有效:
$('#products.table tr').click ->
$(@).toggleClass('row_selected')
Run Code Online (Sandbox Code Playgroud)
这不是:
$('#products.table tr').live 'click', (event) ->
$(@).toggleClass('row_selected')
Run Code Online (Sandbox Code Playgroud)
浏览器控制台出错:
[Error] TypeError: 'undefined' is not a function (evaluating '$('#products.table tr').live')
ready (products.js, line 10)
fire (jquery.js, line 3049)
fireWith (jquery.js, line 3161)
ready (jquery.js, line 434)
completed (jquery.js, line 105)
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
在咖啡脚本中,我试图弄清楚数组中是否包含某些内容.但似乎无法弄清楚正确的语法.有没有办法做到这一点,而不必迭代它们?
谢谢,
if $(this).val() is in ["needs_cover","comatose"]
$("#head_count").hide()
else
$("#head_count").show()
Run Code Online (Sandbox Code Playgroud) 请原谅我糟糕的javascript知识.
我正在尝试从标记为"已选择"的DOM元素返回一个ID值数组,例如[1,2,4].
<tr data-selected = 'true' data-id = '1'></tr>
<tr data-selected = 'true' data-id = '2'></tr>
<tr data-selected = 'false' data-id = '3'></tr>
<tr data-selected = 'true' data-id = '4'></tr>
Run Code Online (Sandbox Code Playgroud)
我试图为此创建一个coffeescript函数
elems = $("tr[data-selected ='true']").data("id")
alert( elems )
Run Code Online (Sandbox Code Playgroud)
这似乎只返回最后一个元素的data-id值.
如何创建所有ID值的数组?
使用CoffeeScript,我希望能够遍历类的静态方法和变量.更具体地说,我想获得对所有功能的访问权限Math.
我在寻找类似的功能:
for x in Math
console.log (x + ": " + Math[x])
Run Code Online (Sandbox Code Playgroud)
这可能吗?
我的Rails 4应用程序运行咖啡脚本来绘制谷歌地图.乍一看,它似乎不起作用.但是,当我点击浏览器刷新按钮时,地图会像冠军一样加载.这已经过测试,并且正在发生:
来自application.html.erb的标题
<head>
<!-- Boilerplate -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<%= stylesheet_link_tag "normalize.min.css" %>
<%= stylesheet_link_tag "main.css" %>
<%= javascript_include_tag "vendor/modernizr-2.6.2-respond-1.1.0.min.js" %>
<!-- Icon Font -->
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<!-- Google Maps API -->
<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=*********&sensor=true" %>
<!-- Rails -->
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<link href='http://fonts.googleapis.com/css?family=Droid+Sans|Lobster' rel='stylesheet' type='text/css'>
</head>
Run Code Online (Sandbox Code Playgroud)
的application.js
// …Run Code Online (Sandbox Code Playgroud) coffeescript ×10
javascript ×7
jquery ×3
arrays ×1
backbone.js ×1
click ×1
collections ×1
express ×1
fetch ×1
google-maps ×1
http ×1
if-statement ×1
node.js ×1
notepad++ ×1
plugins ×1
turbolinks ×1
typeahead.js ×1