Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript]Stworzenie tabeli za pomocą JQUERY
Forum PHP.pl > Forum > Przedszkole
Randallmaster
W jaki sposób mogę stworzyć tabelę w htmlu z danych poniżej:

<script>
$(function () {
var dataSource = new $.ig.DataSource({
dataSource:
[{ "ProductCategory": "Clothing", "UnitPrice": 12.81, "SellerName": "Stanley Brooker", "Country": "Bulgaria", "City": "Plovdiv", "Date": "01/01/2012", "UnitsSold": 282 },
{ "ProductCategory": "Clothing", "UnitPrice": 49.57, "SellerName": "Elisa Longbottom", "Country": "US", "City": "New York", "Date": "01/05/2013", "UnitsSold": 296 },
{ "ProductCategory": "Bikes", "UnitPrice": 3.56, "SellerName": "Lydia Burson", "Country": "Uruguay", "City": "Ciudad de la Costa", "Date": "01/06/2011", "UnitsSold": 68 },
{ "ProductCategory": "Accessories", "UnitPrice": 85.58, "SellerName": "David Haley", "Country": "UK", "City": "London", "Date": "04/07/2012", "UnitsSold": 293 },
{ "ProductCategory": "Components", "UnitPrice": 18.13, "SellerName": "John Smith", "Country": "Japan", "City": "Yokohama", "Date": "12/08/2012", "UnitsSold": 240 },
{ "ProductCategory": "Clothing", "UnitPrice": 68.33, "SellerName": "Larry Lieb", "Country": "Uruguay", "City": "Ciudad de la Costa", "Date": "05/12/2011", "UnitsSold": 456 },
{ "ProductCategory": "Components", "UnitPrice": 16.05, "SellerName": "Walter Pang", "Country": "Bulgaria", "City": "Sofia", "Date": "02/19/2013", "UnitsSold": 492 }]
});
});
</script>
MWL
Each w jQuery i składasz po kolei w pętlach odpowiednie dane.

https://api.jquery.com/jQuery.each/
Randallmaster
Udało mi się stworzyć tabelę. Mam jeszcze pytanie:

czym różnią się te tablice?:

var dupes = {};
var singles = [];
nospor
Tym ze jedna to nie tablica.....
Pierwsze to obiekt, drugie tablica
Randallmaster
var dataTable = {
rows: "ProductCategory",
columns: "[Date]",
result: "[UnitsSold]"
}

jQuery.each( singles, function( i, val ) {
var row = '<tr><td>' + val.ProductCategory + '<td></tr>'
$( "#tabelka" ).append(row);
});
});

jak w miejscu val.ProductCategory zamiast słowa ProductCategory automatycznie pobierało z tablicy dataTable.rows?
nospor
Tak jak w php...

val[dataTable.rows]
pod warunkiem rzecz jasna ze dataTable bedzie tam widoczne
Randallmaster
Super działa smile.gif

a jak odczytać wartość "sort" z diva ?

<div sort="1"></div>
nospor
skoro uzywasz jQuery to moglbys sie zaprzyjaznic z jego dokumentacją....
attr()
Randallmaster
Dzięki
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.