StevenDevooght / tinyMCE-mention

Mention/Autocomplete plugin for tinyMCE WYSIWYG editor.
http://stevendevooght.github.io/tinyMCE-mention/
220 stars 95 forks source link

multiple delimiters #17

Closed KRademacher closed 9 years ago

KRademacher commented 9 years ago

Not really an issue on your side, more a question, but I can't seem to get your example syntax of multiple delimiters to work. I linked it to a .js file, but it cant get the data for some reason. Would you mind maybe showing a more detailed example? Thanks in advance.

StevenDevooght commented 9 years ago

Normally you just have to implement the source function:

source: function (query, process, delimiter) {
    // Do your ajax call
    // When using multiple delimiters you can alter the query depending on the delimiter used
    if (delimiter === '@') {
       $.getJSON('ajax/users.json', function (data) {
          //call process to show the result
          process(data)
       });
    }
}

Can you post a snippet of your source code?

KRademacher commented 9 years ago

I understand that, that's what I did. All I really need is an example of an ajax call. I got this assignment at my internship, but I never touched ajax and json before, so even after searching the web for multiple hours, I still can't get it to work. That's why showing you a snippet won't do anything, because I don't even know myself what it does. Something I did saw however is that you are missing the closing bracket of $.getJSON, but again, I don't know anything about it.

So please, could you show an example of the function connecting to a file called names.json? I understand if you don't, but I'd appreciate it if you would :)

StevenDevooght commented 9 years ago

There was indeed a typo in the documentation. Good catch!

You can also immediately call process with an array of users.

source: function (query, process, delimiter) {
    if (delimiter === '@') {
          process([
                { name: 'Tyra Porcelli' }, 
                { name: 'Brigid Reddish' },
                { name: 'Ashely Buckler' },
                { name: 'Teddy Whelan' }
           ]);
    }
}

If you're using jQuery the following link explains how to perform an ajax call: http://api.jquery.com/jquery.getjson/

KRademacher commented 9 years ago

That solved it, thanks for your time!