Skip to content

Instantly share code, notes, and snippets.

@ankurkaushal
Last active December 22, 2015 00:19
Show Gist options
  • Save ankurkaushal/55dd21838acb0dd3fb10 to your computer and use it in GitHub Desktop.
Save ankurkaushal/55dd21838acb0dd3fb10 to your computer and use it in GitHub Desktop.
App.js
App = Ember.Application.create();
App.Model = Ember.Object.extend({
});
App.IndexRoute = Ember.Route.extend({
redirect : function() {
this.transitionTo('users');
}
});
App.UsersController = Ember.ObjectController.extend({
actions : {
filteredContent : function() {
var searchText = this.get('searchText'), regex = new RegExp(searchText, 'i');
return this.get('model').filter(function(item) {
return regex.test(item.name);
});
}.property('searchText', 'model')
}
});
App.User = App.Model.extend({
id : null,
name : null,
email : null
});
App.UsersRoute = Ember.Route.extend({
model : function() {
return App.User.findAll();
}
});
App.UserRoute = Ember.Route.extend({
model : function(params) {
//var everyone = this.controllerFor('users');
return App.User.findBy('id', params.user_id);
}
});
App.User.reopenClass({
findAll : function() {
return $.getJSON("user.php", function(data) {
return data.map(function(row) {
return App.User.create(row);
});
});
}
});
App.Router.map(function() {
this.resource('users', function() {
this.resource('user',{path: '/:user_id'});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment