添加两个列表进行选择,默认情况下应选择第一个列表 [英] Adding two lists to selectize, the first one should be selected by default

查看:88
本文介绍了添加两个列表进行选择,默认情况下应选择第一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对selectize有一个小问题,即如何添加两个列表,默认情况下应该选择第一个列表,最终用户可以从第二个列表中以相同的形式选择项目.您可以在下面找到我的代码.如果我添加两次选项,则selectize仅需第二个.)

Hi I've a litle problem with selectize, namely how to add two lists and he first one should be selected by default and enduser can select items from second list in same form. Below you can find my code. If I add two times options selectize takes second one only).

$(document).ready(function(){

    lol = "lol1 , lol2 , lol3"
    var lol = lol.split(',');
    var lol = lol.map(function(x) { return { item: x}; });
    console.log(lol)
    console.log(typeof(lol))

    wtf = "wtf1 , wtf2 , wtf3"
    var wtf = wtf.split(',');
    var wtf = wtf.map(function(x) { return { item: x}; });
    console.log(wtf)
    console.log(typeof(wtf))

     $('#show_tags').selectize({
        plugins: ['remove_button', 'restore_on_backspace'],
        select: true,
        delimiter: ',',
        maxItems: null,
        options: lol,
        options: wtf,
        labelField: 'item',
        valueField: 'item',
        searchField: 'item',
        create: true
    });
});

想法?

推荐答案

您需要使用items为默认情况下应选择的选项提供值的数组(而不是使用两个options数组).选项值由您的valueField设置确定.

You need to use items to provide an array of values for the options that should be selected by default (instead of using two options arrays). Option values are determined by your valueField setting.

例如:

$('#select-id').selectize({
  items: ['1', '2'], // preselected options values
  options: [
    {value: '1', name: 'Item 1'}, // this option will be preselected
    {value: '2', name: 'Item 2'}, // this option will be preselected
    {value: '3', name: 'Item 3'},
    {value: '4', name: 'Item 4'}
  ],
  valueField: 'value',
  labelField: 'name',
  searchField: ['name'],
  delimiter: ',',
  select: true,
  create: true,
  maxItems: null
});

这篇关于添加两个列表进行选择,默认情况下应选择第一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆