我通過點擊按鈕,創建我的Backbone.view動態彈出後工作:在創建動態彈出Сlick功能不會動態元素Ajax調用(骨幹)
var Section = Backbone.View.extend({
className: 'sqs-frontend-overlay-editor-widget-section',
events:{
'click .sqs--section--control__edit': 'Section_control'
},
initialize: function(){
},
render: function(){
this.$el.append(_.template(_section).apply(this.options));
return this.$el;
},
Section_control: function(){
var me = this;
require(['View/Popup/Section_control'], function(_Section_control){
var sec = new _Section_control({popup: popup, sec: me.options.section});
var popup = new Popup({content: sec.render()});
});
}
});
return Section;
我有按鈕,觸發:
events:{
'click .module-invert-mode': 'invert'
},
invert: function(e){
console.log('hello');
if(this.options.sec.hasClass('.module-invert')) {
console.log('yse');
}
this.options.sec.toggleClass('module-invert');
this.options.sec.trigger('invertChange');
},
和按鈕invertChange
觸發:
el.on("invertChange", function(e){
var section = el.parents('section');
var index = section.index();
var model = collection.at(index);
model.set(Helper.sectionToObj(section),{doReload: true})
});
看看在{doReload: true}
功能,我在invertChange
撥打:
change: function(model, options){
me = this;
if(model._changing && options.doReload) {
$.ajax({
url: 'wp-admin/admin-ajax.php',
type: 'post',
data: {
action: 'getShortcode',
shortcode: model.attributes.shortcode
},
success: function (data) {
//var section = $(data);
me.$el.find('section:eq(' + model.collection.indexOf(model) + ')').replaceWith(data);
me.add(model, model.collection);
//me.collection.add({shortcode: model.attributes.shortcode}, {at: section.index()});
}
});
}
},
的問題是,當我創建動態彈出,然後點擊按鈕,invertChange
觸發,Ajax的工作原理只有一次,當我在按鈕彈出再次點擊,AJAX不作品(下一個ajax請求只有在關閉時才起作用,並再次創建動態彈出)。如何在不經常關閉並打開我的動態彈出窗口的情況下調用ajax?謝謝!
嘗試添加'this.delegateEvents()''裏面渲染(解決方案)'方法或'replaceWith()'後內部成功' – 2015-04-05 21:04:41
@EugeneGlova試圖添加內部渲染()或replaceWith()後,但它不適合我( – 20yco 2015-04-06 06:35:45