我确定我做的很简单,但似乎无法找到解释.我的模板中有以下行,它不会向html输出打印任何值:
<%= _.each(@place.get("hash"),(count, tag) -> "#{tag} ") %>
Run Code Online (Sandbox Code Playgroud)
这行是完美地打印到控制台的值:
<%= _.each(@place.get("hash"),(count, tag) -> console.log "#{tag} ") %>
Run Code Online (Sandbox Code Playgroud)
当我尝试使用打印命令并刷新时,谷歌浏览器会抛出一个打印菜单.我该如何解决这个问题
如何使方法"btnClick"私有?
class FirstClass
constructor: ->
$('.btn').click @btnClick
btnClick: =>
alert('Hi from the first class!')
class SecondClass extends FirstClass
btnClick: =>
super()
alert('Hi from the second class!')
@obj = new SecondClass
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如何坚持DRY(手风琴的数量可能很大):
$ ->
$("#accordion-1").accordion
autoHeight: false
navigation: true
$ ->
$("#accordion-2").accordion
autoHeight: false
navigation: true
Run Code Online (Sandbox Code Playgroud) 我已经阅读了几篇关于CoffeeScript OOP的论文.从他们那里,我是否正确理解使用@CoffeeScript中的符号(以及thisJavaScript中的前缀):
我是JS和CS的菜鸟,对不起.他们的理念与我习惯的完全不同.
UPDATE
以下是我读过的信息的参考资料:
只是搜索static.
如何从插入的数组中删除元素push?
animals = []
class Cat
cat = new Cat
animals.push cat
Run Code Online (Sandbox Code Playgroud)
我现在可以这么说了
animals.pull cat
Run Code Online (Sandbox Code Playgroud)
把猫带离阵列?假设cat变量与推入的变量相同.我只想创建一种动态集合..
我有一个正则表达式,我正在运行以过滤表中的行。过滤是用Javascript完成的。
我正在编写coffeescript,但是可以使用Javascript解决方案-我可以自己将其翻译为coffeescript。
我有一个role包含要使用正则表达式过滤的字符串的值。问题在于字符串中role 可能包含也可能未包含“ +”符号。 加号是正则表达式搜索的特殊字符,需要在搜索字符串中转义。
我创建这样的正则表达式搜索字符串(咖啡脚本):
"^"+role+"$"
Run Code Online (Sandbox Code Playgroud)
如何预处理role以转义任何“ +”号,以便正则表达式起作用?
我正在写一个Rails应用程序,它具有以下茉莉花规格:
describe "buttons", ->
beforeEach ->
loadFixtures("foo.html")
alert("beforeEach: " + $("tr.foo").length)
describe ".hide_foo", ->
alert(".hide-foo: " + $("tr.foo").length)
...
expect($("tr.foo")).toBeHidden()
Run Code Online (Sandbox Code Playgroud)
规范因错误而失败:
TypeError: Cannot call method 'expect' of null
Run Code Online (Sandbox Code Playgroud)
所以我提出警报.首先我们看到".hide-foo:0",然后在我关闭之后"beforeEach:44"出现.很明显错误是因为我们在expect加载夹具之前调用了但是......为什么在每个例子之前没有beforeEach执行heck ?
我正在使用jasminerice来使用Rails Asset Pipeline来编译我的Coffeescript.版本:
$ bundle show jasmine && bundle show jasminerice
/home/tmacdonald/.rvm/gems/ruby-1.9.2-p320/gems/jasmine-1.2.0
/home/tmacdonald/.rvm/gems/ruby-1.9.2-p320/gems/jasminerice-0.0.9
Run Code Online (Sandbox Code Playgroud)
谢谢!
这是Backbone和下划线js的新手.
我有一组数组,我想转换为模型集合.
所以它就像
{ {1, 2, 3, 4}, {5, 6, 7, 8}}
Run Code Online (Sandbox Code Playgroud)
第二级数组是进入骨干模型的.现在,我有
collection.reset(_.map(results, (indvidualResults) -> new model(individualResults))
Run Code Online (Sandbox Code Playgroud)
哪个不起作用,当我做一个console.log(collection.pop)我得到一个打印出来的功能.我想这是因为我正在使用一组数组(但我可能是错的).如何将第二个数组转换为模型然后将其放入集合中?
我有这个有效的CoffeeScript,并希望将其转换为LiveScript.有人可以解释为什么它无法转换?还要转换一个吗?
TodoCtrl = (scope) ->
scope.addTodo = ->
scope.todos.push
text: scope.todoText
done: false
scope.todoText = ''
Run Code Online (Sandbox Code Playgroud)
您可以使用它来编译CoffeeScript.
您可以使用它来编译LiveScript.
如果我有一个使用路由器架构的应用程序,我如何获得父路由的控制器?
假设有一条路线
Router: Ember.Router.extend
enableLogging: true
root: Ember.Route.extend
main: Ember.Route.extend
route: '/'
connectOutlets: (router, event) ->
router.get('applicationController').connectOutlet('main')
editor: Ember.Route.extend
route: '/editor'
connectOutlets: (router, event) ->
router.get('mainController').connectOutlet('editor')
Run Code Online (Sandbox Code Playgroud)
那我怎么能EditorController抓住我的MainController?
我试过@get('parentController'),@get('parent')以及@get('controller')没有成功
coffeescript ×10
javascript ×6
backbone.js ×1
collections ×1
datatables ×1
dry ×1
eco ×1
ember.js ×1
jasmine ×1
jquery ×1
livescript ×1
models ×1
unit-testing ×1