2017-01-05 27 views
2

我以編程方式開發TableContainer。 當我按下按鈕時,它會在此TableContent中動態添加一行。 這個新行有一個按鈕來刪除它,如果我推它。從TableContainer刪除行

HTML

<div id="formTableContent" class="tblForm"></div> 

的Javascript

var _tableForm = null; 
_onLoad : function() { 
    this._tableForm = new dojox.layout.TableContainer(
     { 
      cols : 3, 
      customClass :"labelsAndValues",  
      "labelWidth" : "100" 
     }, dojo.byId("formTableContent") 
    ); 

    this._tableForm.startup(); 
}, 


// This method add a new row in TableContainer 
_createRow : function() { 
    var txtBox1 = new dijit.form.TextBox({ label : "textlabel1" }); 
    var txtBox2 = new dijit.form.TextBox({ label : "textlabel2" }); 
    var btnDelete = new dijit.form.Button({ label : "Delete", spanLabel : true, iconClass : "removeIcon" }); 
     dojo.connect(btnDelete, "onClick", this, function(evt) { 
      var row = evt.path[5]; 
      row.parentNode.removeChild(row); 
     }); 

    this._tableForm.addChild(txtBox1); 
    this._tableForm.addChild(txtBox2); 
    this._tableForm.addChild(btnDelete); 
    this._tableForm._initialized = false; 
    this._tableForm._started = false; 
    this._tableForm.startup(); 
}, 

圖像例

在事件「的onClick「我試着這樣做:

dojo.connect(btnDelete, "onClick", this, function(evt){ 
    var row = evt.path[5]; 
    row.parentNode.removeChild(row); 
}); 

它deteles行,但是當我添加一個新行,在TableContainer出現的行刪除,新行增加。

回答

0

我知道這是一箇舊帖子,但這可能有助於其他人。 TableContainer有一個方法removeChild(child),如果使用它,該行將被刪除,並且在添加新行時不會再出現。