2012-02-07 71 views
0

爲什麼當我運行我的代碼時顯示重複的內容?我使用empty()來刪除重新運行的以前的記錄,但它似乎並沒有工作。重複記錄顯示

這裏是我的代碼:

function listClass() { 
this.formOrderList = null; 
this.orderListDialogObject = $('<div id="mainDiv"></div>'); 
this.orderListTable = $('<div>' 
    + '<table id="orderListTable" class="ui-widget tblBorder" width="100%" border="0" cellspacing="1" cellpadding="2">' 
    + '<thead class="ui-widget-header" id="orderListHead">' + '<tr>' 
    + '<th><strong> Order# </strong></th>' 
    + '<th><strong> Symbol </strong></th>' 
    //+ '<th><strong> Exchange </strong></th>' 
    //+ '<th><strong> Market </strong></th>' 
    + '<th><strong> Time </strong></th>'    
    + '<th><strong> Order Type </strong></th>' 
    + '<th><strong> Side </strong></th>' 
    + '<th><strong> Volume </strong></th>' 
    + '<th><strong> Price </strong></th>' 
    + '<th><strong> Trigger Price </strong></th>' 
    + '<th><strong> Filled Volume </strong></th>' 
    + '<th><strong> Status </strong></th>' 
    + '<th><strong> Expiry Date </strong></th>' 
    + '<th><strong> Ref # </strong></th>' 
    + '<th><strong> Action </strong></th>' + '</tr>' + '</thead>' 
    + '<tbody id="orderListBody">' + '</tbody>' + '</table>' + '</div>'); 
this.orderListTabs = $('<div>' + '<ul>' 
    + '<li><a href="#pendingOrderList">Pending</a></li>' + '</ul>' 
    + '<div id="pendingOrderList">' + '</div>' + '</div>'); 
this.orderListDialogObject.appendTo("body"); 
this.show = function() { 
$("#orderListBody", this.orderListTable).empty(); 
this.orderListDialogObject.dialog({ 
    title : 'Order List', 
    width : 850, 
    height : 150,   
    close : function(ev, ui) { 
     $(this).remove(); 
     return false; 
     /*$(this).dialog('destroy').remove(); 
     return false;*/ 
    } 
}); 
this.orderListTabs.tabs(); 
this.orderListTabs.appendTo(this.orderListDialogObject);   
$("#pendingOrderList", this.orderListTabs).append(this.orderListTable); 
} 
+0

我已經建立[示例](http://jsfiddle.net/pnNNU/)與您的代碼,但不能[見(HTTP://的jsfiddle .net/pnNNU/show /)重複的內容。 – scessor 2012-02-07 07:25:45

+0

scessor不在thead中,它顯示重複的內容。 – 2012-02-07 07:36:59

+0

哪些函數填充'tbody'?在[這個例子](http://jsfiddle.net/pnNNU/1/show/)([在這裏用代碼](http://jsfiddle.net/pnNNU/1/))你看到一個例子充滿'tbody '和重複的內容沒有問題。 – scessor 2012-02-07 07:52:01

回答

1

你引用this函數裏面,所以它的指向全局對象。

這裏有一個解決方法:

var that = this; 
this.show = function() { 
$("#orderListBody", that.orderListTable).empty(); 
that.orderListDialogObject.dialog({ 
    title : 'Order List', 
    width : 850, 
    height : 150,   
    close : function(ev, ui) { 
     $(this).remove(); 
     return false; 
     /*$(this).dialog('destroy').remove(); 
     return false;*/ 
    } 
}); 
+0

外星人,這段代碼已經上課了。 – 2012-02-07 06:50:12

+0

我知道。但是你在一個匿名函數裏引用'this',這個函數沒有綁定到你的類。因此'this'將指向全局對象,可能是'window'。 – AlienWebguy 2012-02-07 08:13:21

+0

我試過了,它也沒有工作。 – 2012-02-07 09:17:32