我有一个页面,我想显示不同的用户组。到目前为止,我正在使用以下内容过滤UsersController (ArrayController)中的组。
users_controller.js.coffee:
App.UsersController = Ember.ArrayController.extend
content: []
group1: (->
@get('model').filterProperty('role', "group1")
).property('model.@each.type')
group2: (->
@get('model').filterProperty('role', "group2")
).property('model.@each.type')
group3: (->
@get('model').filterProperty('role', "group3")
).property('model.@each.type')我能够用下面的(使用Emblem.js)循环遍历用户模板中的每个组。
users.emblem
.role
h3 Group 1
each user in group1
.segment
= link-to 'user' user | #{user.first} #{user.last}
p
span #{user.shortStory}
.role
h3 Group 2
= each user in group2
.segment
= link-to 'user' user | #{user.first} #{user.last}
p
span #{user.shortStory}
.role
h3 Group 3
= each user in group3
.segment
= link-to 'user' user | #{user.first} #{user.last}
p
span #{user.shortStory}每个用户的模型中都有一个“故事”。在UserController上,我有一个名为shortStory的方法,它将它缩短为大约100个字符的片段。(请参阅以下代码)
user_controller.js.coffee
App.UserController = Ember.ObjectController.extend
shortStory: (->
short = @get('story').substring(0, 100)
for i in short by - 1
if i == " "
break
else
short = short.slice( 0, -1)
short
).property('story')我的问题是,我无法让shortStory显示给任何用户。我尝试过许多不同的语法,包括:
span= user.shortStory
span #{user.shortStory}
span= shortStory
span= #{user.shortStory}如果有人知道我如何在视图中遍历UserController过滤器方法时访问UsersController方法,那就太好了。
首先,我也愿意接受对数据进行过滤的其他建议。我还是很新鲜的余烬。
发布于 2013-10-14 18:59:29
找到了这个问题的答案。我能够在每个循环中添加一个itemController=“用户”。效果很好。
https://stackoverflow.com/questions/19365727
复制相似问题