2012-02-07 67 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