Skip to content

Instantly share code, notes, and snippets.

@matthias-k
Forked from initram/controllers.application.js
Last active October 2, 2016 17:49
Show Gist options
  • Save matthias-k/6807d81cbaeb475cdb115ed16b8890d1 to your computer and use it in GitHub Desktop.
Save matthias-k/6807d81cbaeb475cdb115ed16b8890d1 to your computer and use it in GitHub Desktop.
Access parent component in source function
import Ember from 'ember';
import myTemplate from '../templates/suggestion-template'
export default Ember.Controller.extend({
suggestionTemplate: myTemplate,
getDisplayString : function(suggestion) {
if(typeof suggestion === "string")
return suggestion;
return suggestion.text;
},
updateValue: function(newValue){
this.set('searchInput', getDisplayString(newValue))
},
actions: {
suggestSource: function(query, syncResults, asyncResults) {
// this should be the this controller
// but it seems to be the
// jquery typeahead component
console.log("this", this);
if(query == 'test')
syncResults([{id: 2, text: "testing is fun!"}]);
else
syncResults([{id: 1, text: "test"}]);
},
}
});
{{aupac-typeahead
action=(action updateValue)
class='form-control'
source=(action 'suggestSource')
placeholder='Search...'
allowFreeInput=true
display=getDisplayString
transformSelection=getDisplayString
suggestionTemplate=suggestionTemplate
}}
{{outlet}}
{
"version": "0.10.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.6.0",
"ember-data": "2.6.1",
"ember-template-compiler": "2.6.0"
},
"addons": {
"ember-aupac-typeahead": "2.0.7"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment