由於阿賈克斯加載的內容,我不得不改變功能:PrototypeJS Element.prototype.appendChild問題
document.observe('dom:loaded',function() {
$$('.userListHeaderCell').invoke('observe', 'click', function() {
this.toggleClassName('desc');
var colnumber = this.up().childElements().indexOf(this);
var content = this.up(2);
sortColumn(content, colnumber, this.hasClassName('desc'));
});
});
TO:
document.observe('click', function(e, el) {
if (el = e.findElement('.userListHeaderCell.sortable')) {
el.toggleClassName('desc');
var colnumber = el.up().childElements().indexOf(el);
var content = el.up(2);
sortColumn(content, colnumber, el.hasClassName('desc'));
}
});
的sortColumn樣子:
function sortColumn(content, colnumber, desc) {
content.select('.userListRow').sort(function(a,b){
var atext = a.down(colnumber).innerHTML.stripTags().toLowerCase();
var btext = b.down(colnumber).innerHTML.stripTags().toLowerCase();
return atext.localeCompare(btext) * (desc ? -1 : 1);
}).each(Element.prototype.appendChild, content);
}
切換和colnumber工作和內容是一個對象HTMLDivElement,但似乎我需要轉換內容變量或使用其他r函數,但不知道sortColumn中的內容。我得到的錯誤是:
「無法轉換JavaScript引」 nsresult: 「0x80570009(NS_ERROR_XPC_BAD_CONVERT_JS)」 的位置: 「JS框架:: https://www.someurl.com/scripts/prototype.js :: ::行804」 的數據:無]
做什麼我需要改變才能完成這項工作?
謝謝。
編輯:
在IE錯誤顯示: 無法獲取財產「呼叫」的值:對象爲空或未定義的prototype.js,線路804字符9
我相信這個問題是Element.prototype.appendChild
試過添加Element.extend(內容),但似乎沒有幫助。
示例數據:
<div id="contentbox_Users" class="userList">
<div class="userListHeader">
<div class="userListHeaderCell col1 sortable">First Name</div>
<div class="userListHeaderCell col2 sortable">Last Name</div>
</div>
<div id="contentbox_People">
<div class="userListRow">
<div class="userListCell col1">John</div>
<div class="userListCell col2">Smith</div>
</div>
<div class="userListRow">
<div class="userListCell col1">Bob</div>
<div class="userListCell col2">Ray</div>
</div>
<div class="userListRow">
<div class="userListCell col1">Fred</div>
<div class="userListCell col2">Jones</div>
</div>
</div>
</div>
如果沒有HTML,很難判斷腳本是否選擇了正確的元素。像這樣的錯誤通常意味着元素無法找到。 –
發佈了HTML,謝謝。 – fanfavorite
在CSS上爲「desc」放置一個邊框,並在添加類名稱時查看選定的元素。看到發生了什麼可能會有所幫助。 –