Last active
August 29, 2019 23:43
-
-
Save kumkanillam/efc7d4256c64714cee8ea259699bdf2c to your computer and use it in GitHub Desktop.
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.Component.extend({ | |
searchPosts: Ember.computed('[email protected]', 'search', function() { | |
var posts = this.get('posts'); | |
var search = this.get('search'); | |
return posts.filter(post => post.name.includes(search)); | |
}), | |
categoryPosts: Ember.computed('posts.[]','category', function(){ | |
return this.get('posts').filter(post => post.categoryId === this.get('category')); | |
}), | |
postsFiltered: Ember.computed('searchPosts', 'categoryPosts.[]', 'search', function() { | |
if (this.get('search')) { | |
return this.get('searchPosts'); | |
} else { | |
return this.get('categoryPosts'); | |
} | |
}), | |
/* | |
postsFiltered: Ember.computed('category', 'search', function () { | |
var posts = this.get('posts'); | |
var search = this.get('search'); | |
console.log('computed postsFiltered() with category: ' + this.get('category') + ', search: ' + search); | |
return posts.filter((item) => item['categoryId'] === this.get('category')); | |
// or this when I search, but I don't know how to do: | |
// return posts.filter((item) => item['name'].includes(search)) | |
}) */ | |
}); |
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', | |
category: null, | |
search:'', | |
categories: [{name: 'Category 1', id: 1}, {name: 'Category 2', id: 2}, {name: 'Category 3', id: 3}], | |
posts: [{name: 'Post 1', categoryId: 1}, {name: 'Post 2', categoryId: 2}, {name: 'Post 3', categoryId: 2}, {name: 'Post 4', categoryId: 3}], | |
actions: { | |
clickCategory(categoryId) { | |
this.set('category', categoryId); | |
this.set('search',''); | |
} | |
} | |
}); |
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.11.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.11.0", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.11.0", | |
"ember-testing": "2.11.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment