简体   繁体   中英

Curly brackets in array values, Javascript

I'm having problems getting this autocomplete function to work when my array values begin and end with curly brackets.

Say I have an array with values like this:

var hints = ["{{ticket_id}}","{{requestor_id}}","{{date_created}}"]

Here's my JS:

<script>
    $(document).ready(function() {
        $("#editor_subject").summernote({
            toolbar: [],
            hint: {
               words: hints,
               match: /\b(\w{1,})$/,
               search: function (keyword, callback) {
                 callback($.grep(this.words, function (item) {
                   return item.indexOf(keyword) === 0;
                 }));
               }
             }                
        });
    });
</script> 

So the they way it should work, is if I type something like {{ti it should autocomplete and fill in the rest of the word with {{ticket_id}}, but it's not working. If I remove the curly brackets from the values in the array, it works just fine.

How can I accomplish this? I'm assuming its the regexp used in the match section.

Thanks,

This regex ended up working for me:

/(.{1,})$/

The 2 mentioned above did not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM