我有一個表字段,我動態填充。創建一個對象數組Jquery
<table id="list" class="table table-striped ui-widget ui-widget-content">
<thead>
<tr class="ui-widget-header">
<th>Id</th>
<th>Name</th>
<th>Type</th>
<th>Expression</th>
<th>Variable</th>
<th>Default</th>
<th>Date pattern</th>
<th>Readable</th>
<th>Writable</th>
<th>Required</th>
</tr>
</thead>
<tbody>
</tbody>
我與我的數據從對話框模式得到填充它。 這是我使用來填充該表
$("#list tbody").append("<tr>"+
"<td>" + id.val() + "</td>" +
"<td>" + name_re.val() + "</td>" +
"<td>" + type.val() + "</td>" +
"<td>" + expression.val() + "</td>" +
"<td>" + variable.val() + "</td>" +
"<td>" + defaut.val() + "</td>" +
"<td>" + pattern.val() + "</td>" +
"<td>" + readable + "</td>" +
"<td>" + writable + "</td>" +
"<td>" + required + "</td>" +
"<td>" +"<button type='button' class='removebutton' title='Remove this propertie'>"+"</button>" +
"<button type='button' class='editbutton' title='Edit this propertie'>"+"</button>" +
"<button type='button' class='savebutton' title='save propertie changes'>"+"</button>" +"</td>"+
"</tr>"
);
現在我創建的函數從表中獲取的數據,並將它們推入對象的數組,因爲每個對象表示單個行的從數據的功能桌子。 這是我使用來獲取數據的功能
function getPropertiesListData(){
var propertiesList=[];
var id,
type,
expression,
variable,
defaut,
pattern,
readable,
writable,
required,
name;
$("#list").find('tr').each(function(){
var $tds=$(this).find('td');
propertiesList.push({
id:$tds.eq(0).text();
name:$tds.eq(1).text();
type:$tds.eq(2).text();
expression:$tds.eq(3).text();
variable:$tds.eq(4).text();
defaut:$tds.eq(5).text();
pattern:$tds.eq(6).text();
readable:$tds.eq(7).text();
writable:$tds.eq(8).text();
required:$tds.eq(9).text();
});
});
return propertiesList;}
但是當我跑,我在導航控制檯
Uncaught SyntaxError: Unexpected token ;
這個錯誤是關於該行的輸出這個錯誤:
id:$tds.eq(0).text();
你能幫我解決這個問題,或者告訴我我錯在哪兒,或者告訴我一種從表中獲取數據並將它們存儲到數組中的方法。
使用','分隔對象屬性,而不是';'。以打字錯誤結束。 –
在對象中用逗號','替換分號';'。 – Jer
是的,取代了;與,解決了我的錯誤;謝謝 –