0
我正在使用localstorage作爲項目,並試圖使用tablesorter2 jquery插件對錶進行排序。我不斷收到以下錯誤:已從本地存儲中添加的排序錶行
遺漏的類型錯誤:無法讀取屬性「行」的不確定
我有一個提交按鈕點擊,從localStorage的,我的友好JavaScript控制檯認爲不添加這些行運行功能存在。
有沒有辦法調用從localstorage添加的行,而不是原始標記中的行?
下面的代碼添加錶行:
$(document).ready(function(){
$.extend($.fn, {
storeitem: function() {
//add a new id for each array
$newTeam = $('#team');
//set up unique ids for each array
var i = Number(localStorage.getItem('team-counter')) + 1;
// create condition to add or loop through new entry
if ($newTeam.val() !== "") {
// Take the value of the input field and save it to localStorage
localStorage.setItem("team-" + i, $newTeam.val());
// Set the to-do max counter so on page refresh it keeps going up instead of reset
localStorage.setItem('team-counter', i);
}
//use serializeArray to simplify array creation
// var teaminfo = $("#newTeamForm").serializeArray();
var teaminfo = {};
var givemethat = $.each($('#newTeamForm').serializeArray(), function() {
teaminfo[this.name] = this.value;
});
//alert(teaminfo.teamname);
//$('div.second').replaceWith('<h2>New heading</h2>');
$("#standings tr:last-child").after('<tbody><tr><td>' + teaminfo.teamname + '</td> <td></td><td></td> <td></td></tr></tbody>');
$("#standings").tablesorter();
//$("#standings > tbody:last").after("<tr>" + + "</tr>");
//store data in key value pair and stringify
localStorage.setItem("team-" + i, JSON.stringify(teaminfo));
// var neat = localStorage.setItem('teamname')
var teamName = JSON.parse(localStorage.getItem("team-" + i));
}//storeitem
});//extend
});//doc ready
要運行的排序功能,我跑:
$('#standings').tablesorter();
當我手動添加錶行到我的標記功能的工作,但當使用上面的函數從localstorage中添加它們時。
請讓我知道這是否合理。我是一名新開發人員,請原諒模糊不清。
向我們展示您用來插入本地存儲的代碼,並向我們顯示您正在使用的代碼,從而產生錯誤。這些是難題的關鍵部分,並可能導致更多的人對解決您的問題感興趣。 – Ohgodwhy 2012-08-10 03:38:46
爲什麼這個問題在沒有特定原因的情況下被修改?這是編程有關和確定,如果有點模糊。 – 2012-08-10 03:58:52