2017-12-18 114 views
0

我想从选项jQuery的 - 如何设置semanic UI下拉值

statuses = [ 
    { value: 'all', name: 'All' }, 
    { value: true, name: 'Received' }, 
    { value: false , name: 'Not Yet' } 
]; 

// my jquery doesn't work 
if (params['invoiceStatus'] && params['invoiceStatus'] !== '') { 
    this.args.invoiceStatus = params['invoiceStatus']; 
    $('#invoiceStatus').dropdown(
     'set selected', params['invoiceStatus']); 
} else { 
    $('#invoiceStatus').dropdown('all'); 
} 

阵列设置一个值下拉我加入这个jQuery:

if (params['invoiceStatus'] && params['invoiceStatus'] !== '') 
{ 
    this.args.invoiceStatus = params['invoiceStatus']; 
    $('#invoiceStatus').dropdown('set selected', params['invoiceStatus']); 
} 
else { 
    $('#invoiceStatus').dropdown('all'); 
} 

但不工作

回答

0

https://semantic-ui.com/modules/dropdown.html#/usage

根据语意UI的文档,如果你想有创建dropd拥有与所选值:

var selectedHelper = function (params, name) { 
    if (params['invoiceStatus'] === name) return true; 
    return false; 
} 

var statuses = [ 
    { 
     value: 'all', 
     name: 'All', 
     selected: selectedHelper(params, 'All'), 
    }, 
    { 
     value: true, 
     name: 'Received' 
     selected: selectedHelper(params, 'Received'), 
    }, 
    { 
     value: false, 
     name: 'Not Yet' 
     selected: selectedHelper(params, 'Not Yet'), 
    } 
]; 

$('#invoiceStatus').dropdown({ values: statuses }); 
+0

,但我想在'PARAMS [“invoiceStatus”]使用的值' – CMB

+0

我更新了我的一个辅助函数的答案,它需要params对象和任何你的名字正在检查 – zepdrix