Spine JS 使用 Hem 渲染 .eco 模板时出错:“无法读取属性‘长度’”未定义的”
学习spine.js 我毫无问题地完成了两个教程,似乎是一个很棒的框架,但是这个简单的小问题让我发疯,因为我不知道我能做些什么来解决它......
根据我对变量@的理解list 应该可以通过 .eco 模板(由 hem 编译)访问,但事实并非如此,还有其他人遇到过这个吗?
有人可以告诉我哪里出错了吗?
Users.coffee
Spine = require('spine')
User = require('models/user')
$ = Spine.$
class Show extends Spine.Controller
className: 'UserApp'
events:
'click .NewUser' : 'new'
constructor: ->
super
User.bind('create refresh change', @render)
@active @render
render: =>
#get all users and render list
@list= [1,2,3,4,5]
console.log(@list)
@html require('views/UserApp')(@list)
new: ->
@navigate('/users','create')
UserApp.eco
<% if @list.length: %>
<% for i in @list: %>
<%= i %>
<% end %>
<% else: %>
Why you no work!?
<% end %>
Learning spine.js I completed both the tutorials no problem, seems like a great framework, but this simple little problem is driving me nuts, because I have no idea what I can do to fix it...
From what I understand the variable @list should be accessible by the .eco template (compiled by hem), but it's not, has anybody else encountered this?
Can someone please show me where I am going wrong?
Users.coffee
Spine = require('spine')
User = require('models/user')
$ = Spine.$
class Show extends Spine.Controller
className: 'UserApp'
events:
'click .NewUser' : 'new'
constructor: ->
super
User.bind('create refresh change', @render)
@active @render
render: =>
#get all users and render list
@list= [1,2,3,4,5]
console.log(@list)
@html require('views/UserApp')(@list)
new: ->
@navigate('/users','create')
UserApp.eco
<% if @list.length: %>
<% for i in @list: %>
<%= i %>
<% end %>
<% else: %>
Why you no work!?
<% end %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
需要一个哈希对象作为参数。因此,如果你想在视图中使用 @list 变量(我的意思是 Rails),你必须执行如下操作:
其中键是视图中变量的名称。因此,使用:
就像您所做的那样,会将
@list
变量作为当前@
或this
带到视图中,并且在您的视图中您应该能够通过以下方式使用它:但它的可读性不那么好。
expects an hash object as parameter. So, if you want to use a
@list
variable in your view (ala Rails I mean) you have to do something like the following:where the key will be the name of your variable in the view. So using:
like you're doing will bring to the view the
@list
variable as the current@
orthis
and in your view you should be able to use it in the following way:But it's not that readable.
我认为模板期望接收一个对象。然后,您可以使用
@key_name
访问该对象的属性;尝试这样的事情(免责声明:我不知道 Coffeescript )
I think the template expects to receive an object. Then you access a property of that object by using
@key_name
;Try something like this ( Disclaimer: I don't know Coffeescript )