Last active
August 29, 2015 14:25
-
-
Save koriroys/97f3ea8d22afa9a7ba69 to your computer and use it in GitHub Desktop.
Query params don't work
This file contains hidden or 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 DS from "ember-data"; | |
export default DS.FixtureAdapter.extend({ | |
queryFixtures: function(fixtures, query, type) { | |
console.log(query); | |
console.log(type); | |
if (!query) { | |
return fixtures; | |
} | |
return fixtures.filter(function(item) { | |
for(var prop in query) { | |
if( item[prop] != query[prop]) { | |
return false; | |
} | |
} | |
return true; | |
}); | |
} | |
}); |
This file contains hidden or 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', | |
actions: { | |
loadSecretBook: function() { | |
this.transitionToRoute('books', { queryParams: { secretCode: "12345" } }); | |
} | |
} | |
}); |
This file contains hidden or 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
export default Ember.Controller.extend({ | |
queryParams: ['secretCode'], | |
secretCode: null | |
}); |
This file contains hidden or 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'; | |
import DS from 'ember-data'; | |
var Book = DS.Model.extend({ | |
title: DS.attr('string'), | |
secret_code: DS.attr('string') | |
}); | |
Book.reopenClass({ | |
FIXTURES: [ | |
{id: 1, title: "Ender's Game"}, | |
{id: 2, title: "War and Peace"}, | |
{id: 3, title: "Game of Thrones 6", secretCode: "12345"} | |
] | |
}); | |
export default Book; |
This file contains hidden or 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'; | |
var Router = Ember.Router.extend({ | |
location: 'none' | |
}); | |
Router.map(function() { | |
this.route('books'); | |
}); | |
export default Router; |
This file contains hidden or 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
export default Ember.Route.extend({ | |
queryParams: { | |
secretCode: { | |
refreshModel: true | |
} | |
}, | |
model: function(params) { | |
if (Ember.isPresent(params.secretCode)) { | |
return this.store.query('book', { secretCode: params.secretCode }); | |
} else { | |
return this.store.findAll('book').then(function(books){ | |
return books.filter(function(book) { | |
return Ember.isEmpty(book.get('secretCode')); | |
}); | |
}); | |
} | |
} | |
}); |
This file contains hidden or 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
{ | |
books: [ | |
{ id: 1, title: "Ender's Game" }, | |
{ id: 2, title: "War and Peace" }, | |
{ id: 3, title: "Game of Thrones 6", secretCode: "12345" } | |
] | |
} |
This file contains hidden or 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
body { margin: 12px 16px } |
This file contains hidden or 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.7", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.6/ember.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.7/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.6/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment