简体   繁体   English

数组值中的花括号,JavaScript

[英]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: 这是我的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. 因此,它们应该起作用的方式是,如果我键入类似{{ti的内容,它将自动完成并用{{ticket_id}}填充单词的其余部分,但它不起作用。 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,})$/ /(.{1,})$/

The 2 mentioned above did not. 上面提到的2没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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