I am using Mention.js on my site, which populates a dropdown list of usernames when "@" is typed in an assigned textarea.
<textarea id="full"></textarea>
It's working great but the examples only show how to embed the JSON data on the actual page like this :
<script type="text/javascript">
$(document).ready(function(){
$("#full").mention({
users: [{
name: 'Rick Bahner',
username: 'RickyBahner',
image: 'http://placekitten.com/25/23'
}, {
name: 'Jacob Kelley',
username: 'jakiestfu',
image: 'http://placekitten.com/25/22'
}, {
name: 'John Doe',
username: 'HackMurphy',
image: 'http://placekitten.com/25/21'
}, {
name: 'Loud Mouth Burrito',
username: 'Loudmouthfoods',
image: 'http://placekitten.com/21/20'
}]
});
});
</script>
I don't want to embed it, I have my JSON data stored in a separate file called myresults.json and I'd like to load that file instead.
I'm trying this but I don't think I'm doing it right as it's not working.
<script type="text/javascript">
$(document).ready(function(){
$("#full").mention({source: 'myresults.json'})
});
EDIT Here is my updated call, thanks to Eric :
<script type="text/javascript">
$(document).ready(function(){
$.getJSON('myresults.json', function(__data){
$("#full").mention({source:__data.users})
});
});
</script>
But it's still not working so I've created a fiddle with both embedded and JSON load methods. Maybe somebody can work out why the JSON version isn't working?