Last active
November 30, 2015 10:15
-
-
Save nightire/6355950e9d06d9f83349 to your computer and use it in GitHub Desktop.
CP based QP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
const today = new Date().toLocaleDateString().split('/').join('-'); | |
export default Ember.Controller.extend({ | |
today, | |
queryParams: ['date'], | |
// date can be used in query-params helper | |
date: today, | |
// dateParam is the middle transform layer, | |
// typically you don't need use it directly, | |
// but if you want to change `date` in code, | |
// you should set `dateParam` instead of `date` like `setDate()` action did | |
dateParam: Ember.computed('model.date', { | |
get(k) { | |
let v = this.get('model.date'); | |
this.set('date', v ? v.split('/').join('-') : null); | |
return v; | |
}, | |
set(k, v) { | |
this.set('date', v ? v.split('/').join('-') : null); | |
return v; | |
} | |
}), | |
actions: { | |
setDate(date) { | |
this.set('dateParam', date); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
queryParams: { | |
date: { refreshModel: true } | |
}, | |
model(params) { | |
const date = params.date ? params.date.split('-').join('/') : null; | |
/** | |
* you can enable this to simulate the default value from API | |
* | |
const date = params.date ? params.date.split('-').join('/') : '2015/11/30'; | |
*/ | |
return { date } | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.4.16", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment