I am using Ember App Kit not ember -cli
I am getting some response from the server like [{date: '2014-01-15T16:22:16-08:00', message: 'Tidal wave occurred'}, {date: '2014-01-15T05:00:16-08:00', message: 'Tornado destroyed town'}, {date: '2014-01-13T14:22:16-08:00', message: 'Volcanic eruption, likely'}, {date: '2014-01-13T16:24:16-08:00', message: 'Ice shelf calving off completely'}, {date: '2014-01-11T11:27:26-08:00', message: 'Mother-in-law visiting'}]
And I am trying to group it by date so that the output looks like
`Today
----------
4:22 pm - Tidal wave occurred
5:00 am - Tornado destroyed town
Monday
----------
2:22 pm - Volcanic eruption, likely
This is my model app/model
`Model = DS.Model.extend
date: DS.attr "string"
message: DS.attr "string"
`export default Model`
This is my route --app/routes/test
Route = Ember.Route.extend
model: () ->
return @store.find "my-model"
`export default Route`
This is my mixin to group by date --app/mixin/groupable-mixin.coffee
Mixin = Ember.Mixin.create
group: null
ungroupedContent: null
groupedContent: (->
model = @
groupedContent = Ember.A([])
groupCallback = @get('group')
ungroupedContent = @get('ungroupedContent')
return groupedContent unless groupCallback
return groupedContent unless ungroupedContent
ungroupedContent.forEach (item) ->
group = groupCallback.call(model, item)
return unless groupKey = group.get('key')
foundGroup = groupedContent.findProperty('group.key', groupKey)
unless foundGroup
foundGroup = groupedContent.pushObject Ember.ArrayProxy.create
group: group,
content: Ember.A([])
foundGroup.get('content').pushObject(item)
groupedContent
).property('group', 'ungroupedContent.@each')
`export default Mixin`
This is my controller app/controller/test.coffee
'import GroupMixin from "app/mixins/groupable-mixin" '
Controller = Ember.ArrayController.extend GroupMixin,
ungroupedContentBinding: 'content' # tell Groupable where your default content is
# the callback that will be called for every
# item in your content array -
# just return the same 'key' to put it in the same group
group: (activity) ->
Ember.Object.create
key: moment.utc(activity.get('date')).format('YYYY-MM-DD') # using momentjs to pluck the day from the date
description: 'some string describing this group (if you want)'
# Controller = Em.ArrayController.extend()
`export default Controller`
And this is my template-app/templates/test.hbs
{{#each groupedContent}}
{{group.key}} - {{group.description}}
{{#each content}}
{{message}}
{{/each}}
{{/each}}
However when i do grunt server I get the following response
Warning: Error compiling tmp/javascript/app/mixins/groupable-mixin.js Used --force, continuing.
And when I do grunt server --force I see the following
Ho wo resolve this .Am i using mixin correctly.Am i importing the mixin correctly in controller?
Aucun commentaire:
Enregistrer un commentaire