Tip 1.1 : Select2コントロールの内容を再度初期化せずに更新する
//ajaxを実行して新内容を取得する
success:function (result, textStatus, xhr) {
if(result.success){
$items = result.items;
//元のコンテンツをクリアする
$('#opt-select2').html('').select2({data: [{id: null, text: null}]});
var data = [];
jQuery.each($items, function(key, value){
var item_obj = value;
data.push({id:item.id, text: item.text});
});
$("#opt-select2").html('').select2({data: $(data)});
}else{
...
}
Tip 1.2 : Select2のPlaceholderをjQueryで設定する
//ajaxを実行して新内容を取得する
success:function (result, textStatus, xhr) {
if(result.success){
$items = result.items;
//元のコンテンツをクリアする
$('#opt-select2').html('').select2({data: [{id: null, text: null}]});
var data = [id:'', text:'']; //Placeholderを表示するように用意する
jQuery.each($items, function(key, value){
var item_obj = value;
data.push({id:item.id, text: item.text});
});
$("#opt-select2").html('').select2({data: $(data)});
$("#opt-select2").select2({placeholder: 'New Place holder', allowClear:true});
}else{
...
}
Tip 2: Bootstrap wysihtml5-editorの内容を設定する
var iframe = $('#wysihtml5-editor-div').find('iframe');
//書かれていた内容を削除する
$(iframe).contents().find('.wysihtml5-editor').html('');
//新内容を記入する
$('#wysihtml5-editor-div').data("wysihtml5").editor.setValue($new_content);
Tip3 : AdminLTEに含むBootstrap wysihtml5-editorライブラリのバグ
Tip2で参照されていたeditorはいつもnullである場合は使っているライブラリを確認してください。一応最新版のAdminLTEに含むライブラリだとこの既存バグは存在されています。修正法は以下になります。
bootstrap-wysihtml5.js
createEditor: function(options) {
options = options || {};
// Add the toolbar to a clone of the options object so multiple instances
// of the WYISYWG don't break because "toolbar" is already defined
options = $.extend(true, {}, options);
options.toolbar = this.toolbar[0];
var editor = new wysi.Editor(this.el[0], options);
if(options && options.events) {
for(var eventName in options.events) {
editor.on(eventName, options.events[eventName]);
}
}
return editor; //<ーこのラインを追加する
},
あるいは修正した版をダウンロードして切り替える
bootstrap-wysihtml5