Closed pravin-d closed 9 years ago
After updating the data-content attr in
Can you provide me with a jsfiddle?
Both of these are working for me:
$('#city').find('option').eq(0).data('content', 'Test content.').parent().selectpicker('refresh');
\\ or
$('#city').find('option').eq(0).attr('data-content', 'Test content.').parent().selectpicker('refresh');
Yes I have use the first one. I have not tested the second. Let me explain the problem I was facing(as a novice knockout js developer) .
refresh()
does re-read the data-content attribute. reloadLi()
is called within refresh()
. reloadLi()
calls createLi()
which runs through all of the options and recreates them, including any data attributes set on the options. If you can provide me with an example where this isn't happening as it should be, please link me to it. What version of bootstrap-select are you using?
try to replace with a html
<input type='text' class='bss-input' id='bss-input-175a15d7376' onKeyDown='event.stopPropagation();' onKeyPress='selectPicker.addSelectInpKeyPress(this,event)' onClick='event.stopPropagation()' onkeyup='selectPicker.editSelectItem(this,\'175a15d7376\')' value='adad'/>
full option
version: 1.13.14
Can you provide me with a jsfiddle?
Both of these are working for me:
$('#city').find('option').eq(0).data('content', 'Test content.').parent().selectpicker('refresh'); \\ or $('#city').find('option').eq(0).attr('data-content', 'Test content.').parent().selectpicker('refresh');
This sample was very helpful. It seems editing the data-content
without jQuery will make it fail. I could confirm this, because data('content', 'Test')
will not change the data-content
on the element itself, but only internal JS as it seems.
I'm using bootstrap and knockoutJS with selectpicker. I want to add a label to the select options, which would change color according to some condition. So I want to know if I can dynamically set the data-content through selectpicker function.