美文网首页
cxselect动态获取数据

cxselect动态获取数据

作者: 平静_b99e | 来源:发表于2019-05-22 17:32 被阅读0次
    1. 常规使用
    # html: data-value默认值
    <div id="cxselect">
        <select name="province" class="form-control province" data-first-title="请选择" data-first-value="0" data-value="{$data.province}">
        <select name="city" class="form-control city" data-first-title="请选择" data-first-value="0" data-value="{$data.city}">
        </select>
    </div>
    
    # js
    var urlChina = 'js/cityData.min.json';
    $('#cxselect').cxSelect({
        url: urlChina,
        selects: ['province', 'city'],
        jsonName: 'n',
        //jsonValue: 'id',
        emptyStyle: 'none'
    });
    
    1. 动态数据
    # html: data-url动态数据源url地址;data-value默认值
    <div id="cxselect" data-url="{$domain}{:url('Area/jsonData')}">
        <select name="province" class="form-control province" data-first-title="请选择" data-first-value="0" data-value="{$data.province}">
        <select name="city" class="form-control city" data-first-title="请选择" data-first-value="0" data-value="{$data.city}">
        </select>
    </div>
    
    #js
    $('#cxselect').cxSelect({
        selects: ['province', 'city'],
        jsonName: 'n',
        // jsonValue: 'id',
        emptyStyle: 'none'
    });
    
    1. api动态数据
    # html: data-value默认值
    <div id="cxselect">
        <select name="province" class="form-control province" data-first-title="请选择" data-first-value="0" data-value="{$data.province}">
        <select name="city" class="form-control city" data-first-title="请选择" data-first-value="0" data-value="{$data.city}">
        </select>
    </div>
    
    # js
    $('#cxselect').cxSelect({
        data:[],
        selects: ['province', 'city'],
        jsonName: 'n',
        jsonValue: 'id',
        emptyStyle: 'none'
    }, function(api) {
        cxSelectApi = api;
    });
    $.ajax({
        url: 'http://www.pengpengzhiyou/area/api',
        type: 'GET',
        dataType: 'json'
    }).done(function(data, textStatus, jqXHR) {
        cxSelectApi.setOptions({
            data: JSON.parse(data),
            selects: ['province', 'city'],
            jsonName: 'n',
            jsonValue: 'id',
            emptyStyle: 'none'
        });
    }).fail(function(jqXHR, textStatus, errorThrown) {
    });
    

    相关文章

      网友评论

          本文标题:cxselect动态获取数据

          本文链接:https://www.haomeiwen.com/subject/paoyzqtx.html