douna2633 2019-06-05 05:08
浏览 73
已采纳

如何从ajax数据创建jquery数组?

I wanna create array from ajax response. I took array from ajax and i have to create dynamic data for chips materializecss autocomplete

response from ajax

var tag = '';
$(document).on('keyup', '.tags', function() {

    var _this = $(this).val();

    if(_this.length > 1) {

        $.ajax({
            url: '/story/searchTags',
            type: 'POST',
            dataType: 'JSON',
            data: {
                tag: _this
            },
            success: function(tags) {
                tag = tags;
            }
        });

    }

});

$('.chips-placeholder').chips({
    placeholder: lang_('Your tag'),
    secondaryPlaceholder: '+ tag',
    autocompleteOptions: {
        // I need data like this from response
        data: {
           'Google', null
           'Googol', null
        },
        limit: 5,
        minLength: 2
    }
});
<div class="chips chips-placeholder chips-autocomplete input-field" style="background:#fff">
   <input class="input tags" placeholder="tag" autocomplete="off" />
</div>

that's my code

Finally, thanks to @Vel to find right answer. jsfiddle - work code

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 ubuntu18.04 tty报错&tty界面su/sudo命令无法执行,如何解决?
      • ¥20 关于c语言网络编程,实现传文件和即时聊天
      • ¥20 下面的压缩方法是否可行
      • ¥15 结构体数组读取文件信息失败,读取不了
      • ¥15 kaldi thchs30 训练遇到问题
      • ¥15 shellter无法使用,如何解决?(操作系统-kali)
      • ¥15 matlab动态模态分解程序
      • ¥60 关于渗透及远控的几个问题
      • ¥15 python文本词汇出现次数统计
      • ¥15 使用按键和串口,记录按键在不消抖的情况下触发的次数