我是Ember世界的新手(来自Backbone/Marionette供电的应用程序),有些事情对我来说还不太清楚.
我想在我的应用程序中渲染3个视图:侧栏,导航和带有实际内容的视图(基于我的路径).
为了做到这一点,我添加到我的应用程序tempalate 3个出口:
<nav id="main_navigation">{{outlet navigation}}</nav>
<!-- some html goes here... -->
<nav id="sidebar_navigation">{{outlet sidebar}}</nav>
<section id="content">{{outlet}}</nav>
Run Code Online (Sandbox Code Playgroud)
因为我想在每个页面上显示它们,所以我使用以下代码创建了ApplicationRoute:
App.ApplicationRoute = Ember.Route.extend
activate: ->
@render "sidebar",
outlet: "sidebar"
# into "application"
Run Code Online (Sandbox Code Playgroud)
当然我有侧边栏模板,但我不认为它的代码在这里是相关的(我可以附加它,如果它是相关的).不幸的是,这会导致以下错误:
Error while loading route: Error: Assertion Failed: An outlet (sidebar) was specified but was not found.
Run Code Online (Sandbox Code Playgroud)
如果我试着评论into "application",那么我得到这个:Error while loading route: TypeError: Cannot read property 'connectOutlet' of undefined
如果有人告诉我如何全局渲染这些模板(在所有页面上),我会非常高兴.
我正在玩Coffeescript,试图将JavaScript文件转换为Coffeescript.这是有效的JavaScript:
element(by.model('query.address')).sendKeys('947');
Run Code Online (Sandbox Code Playgroud)
这是无效的Coffeescript:
element(by.model('query.address')).sendKeys('947')
Run Code Online (Sandbox Code Playgroud)
Coffeescript的无效之处是什么?Coffeelint说"意外的BY".
我正在尝试编写一个grunt任务,使用grunt将许多.coffee文件编译为相应的.js文件和.map文件.我有咕噜咕噜的咖啡插件,但有一些问题:
请帮助解决这些问题:
Grunt插件:https://www.npmjs.org/package/grunt-contrib-coffee
Gruntfile.coffee:
module.exports = (grunt) ->
grunt.initConfig(
pkg: grunt.file.readJSON 'package.json'
coffee:
coffee_to_js:
options:
bare: true
sourceMap: true
expand: true
flatten: true
cwd: "client"
src: ["**/*.coffee"]
dest: 'client'
ext: ".js"
)
#Load Tasks
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.registerTask('compile', ['coffee']);
null
Run Code Online (Sandbox Code Playgroud)
编译Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
coffee: {
coffee_to_js: {
options: {
bare: true,
sourceMap: true
},
expand: true,
flatten: true,
cwd: "client",
src: ["**/*.coffee"],
dest: 'client',
ext: ".js"
}
}
});
grunt.loadNpmTasks('grunt-contrib-coffee');
grunt.registerTask('compile', …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails 4进行Agile Web开发,第11.5节教授如何使图像可点击.我接着是课程,下面是我的store.js.coffee
$(document).on "ready page:change", ->
$('.store .entry > img').click ->
$(this).parent().find(':submit').click()
Run Code Online (Sandbox Code Playgroud)
以上将允许我点击我的商店页面上的图片以将特定项目添加到购物车,但它将"点击"它两次,因此将两个项目添加到购物车而不是仅一个.常规的"添加到购物车"按钮工作正常,所以我不太确定问题出在哪里.
我认为上面的代码不足以查明问题,但我不知道要发布的代码的其他部分,所以如果您需要其他信息,请告诉我.谢谢!
当我打开本地主机时,我收到此ExecJS错误消息,我不知道为什么,一些帮助会很惊人.
显示/.../conektec/app/views/layouts/application.html.erb,其中第6行引发:
SyntaxError:[stdin]:6:16:意外的换行符(在/.../conektec/app/assets/javascripts/orders.js.coffee中)
ActionView::Template::Error (SyntaxError: [stdin]:2:73: unmatched )
(in /Users/hbendev/startups/conektec/conektec/app/assets/javascripts/orders.js.coffee)):
3: <head>
4: <title>Conektec</title>
5: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6: <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7: <%= javascript_include_tag "https://js.stripe.com/v2/" %>
8: <%= csrf_meta_tags %>
9: <%= tag :meta, :name => "stripe-key", :content => ENV["STRIPE_PUBLIC_KEY"] %>
Run Code Online (Sandbox Code Playgroud)
jQuery ->
Stripe.setPublishableKey($('meta[name="stripe-key"]').attr('content'))
payment.setupForm()
payment =
setupForm: ->
$('#new_order').submit ->
$('input[type=submit]').attr('disabled', true)
Stripe.card.createToken($('#new_order'), payment.handleStripeResponse)
false
handleStripeResponse: (status, response) ->
if status == 200 …Run Code Online (Sandbox Code Playgroud) 我正在使用jQuery Validate插件进行验证.我必须在表单上进行实时验证.例如,如果需要名字,那么用户应该首次获得所需的消息,并在他开始输入文本框时进入.
为了实现这个功能,我正在使用插件onkeyup和onfocusout选项.为此,我引用了具有相同问题的链接.
这是我用于表单验证的coffeescript代码
defaultPageForm: (self)->
form = $("#PageForm")
if form.length > 0
form.find('textarea').on 'click', -> $(@).valid()
form.find('input').on 'click', -> $(@).valid()
form.validate
ignore: ".ignore"
rules:
"view[name]":
required: true
NameWordCount: [3]
"view[comment]":
required: true
CommentWordCount: [5]
accept_terms: "required"
messages:
"view[comment]": "Please add comment"
errorElement: "span"
errorClass: "error_msg wide "
errorPlacement: (error, element) ->
element.siblings(".view_form_error_msg").remove()
error.appendTo element.closest(".controls")
return
###### Real time validation code #############
onkeyup: (element) ->
$(element).valid()
return
onfocusout: (element) -> …Run Code Online (Sandbox Code Playgroud) 在使用CoffeeScript创建AngularJS指令时,我使用了这种方法:
angular
.module('MyApp', [])
.directive 'myDirective', ->
restrict: 'E'
controllerAs: 'ctrl'
controller: ->
new class
constructor: ->
@value = 3
Run Code Online (Sandbox Code Playgroud)
此代码适用于Angular 1.2.14- jsbin,但不适用于1.3.0- jsbin.我在控制台中没有任何错误,只是它什么也没做.看起来控制器是一个空对象.
我试图访问图像:app/assets/images/rails/png,在我的CoffeeScript文件中但使用
<img src='assets/images/rails.png' width='30' height='30'>
产生控制台错误:

如何从CoffeeScript访问存储在我的图像文件中的图像?
我正在构建一个木偶项目视图,这是一个a元素.
我想知道如何a使用Mationette 获取有效元素,因为我的代码没有设置href属性:
class CategoryFilters.ItemView extends App.Views.ItemView
tagName: "a"
className: "btn btn-primary"
template: "topics/categoryFilter/filter-item"
triggers:
"click": "filter:clicked"
Run Code Online (Sandbox Code Playgroud)
给出了结果:
<a class="btn btn-primary">company</a>
Run Code Online (Sandbox Code Playgroud)
它看起来不错,但这个标签没有href属性.
如何href="#"以干净的方式设置此视图?
我正在尝试获取一个输入类型的选定值,每次都会出现此错误:Uncaught TypeError: Cannot assign to read only property 'highlight' of.它永远不会告诉我它指的是什么对象,它来自TypeAhead.min.js文件,所以我不能确切地说我的代码是什么行引起它.这是我用来设置和捕获输入值的代码:
$(".articles.new").ready ->
engine = new Bloodhound {
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
local: autocomplete_items
}
engine.initialize()
$('#auto_complete').typeahead { hint: true, highlight: true, minLength: 1 },
{ name: "names", displayKey: "name", source: engine.ttAdapter()}
$('#auto_complete').on 'typeahead:selected', (event, selection) ->
alert selection.name
$('#auto_complete').typeahead 'setQuery', ''
event.stopPropagation()
return
return
Run Code Online (Sandbox Code Playgroud)
对于上下文:auto_complete项是来自我的控制器的具有name属性的对象数组.我在Ruby on Rails 4.1.4上工作.
我该怎么做才能解决这个错误?是什么造成的?
coffeescript ×10
javascript ×3
jquery ×2
angularjs ×1
backbone.js ×1
ember.js ×1
gruntjs ×1
image ×1
marionette ×1
node.js ×1
ruby ×1
typeahead ×1
typeahead.js ×1