Tôi đã cấu hình cửa hàng của tôi như sau:ExtJS lỗi lưới, dữ liệu JSON không được hiển thị
var store = new Ext.data.JsonStore({
url: 'gridData.php',
root: 'movies',
fields: ['film_id', 'title', 'release_year', 'rating']
});
và sau đó được xác định lưới của tôi là:
var grid = new Ext.grid.GridPanel({
title:'Movies',
store: store,
columns: [
{ header: "ID", width: 30, dataIndex: 'film_id',sortable: true, hidden:true },
{ id: 'title-col', header: "Title", width: 180,dataIndex: 'title', sortable: true },
{ header: "Rating", width: 75, dataIndex: 'rating',sortable: true },
{ header: "Year", width: 75, dataIndex: 'release_year',sortable: true, align: 'center' }
],
autoExpandColumn: 'title-col',
renderTo: Ext.getBody(),
width: 600,
height: 300,
loadMask: true
});
Sau đó tôi tải các cửa hàng:
store.load();
Tôi đang làm tất cả điều này trong phương thức Ext.onReady
. Dữ liệu mà tôi muốn hiển thị được tải xuống từ tệp php có dạng sau:
{ "count":2, "movies":[{ "film_id":"1", "title":"ACADEMY DINOSAUR", "description":"An Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies", "release_year":"2006", "rating":"PG", "special_features":"Deleted Scenes,Behind the Scenes" }, { "film_id":"2", "title":"ACE GOLDFINGER", "description":"An Astounding Epistle of a Database Administrator And an Explorer who must Find a Car in Ancient China", "release_year":"2006", "rating":"G", "special_features":"Trailers,Deleted Scenes" } ] }
Khi trang được tải, lưới sẽ hiển thị mặt nạ tải và dữ liệu không bao giờ được hiển thị. Ngoài ra, tôi gặp lỗi a is undefined.
Tôi đang thiếu gì?
Sửa
Tôi đã phát hiện ra rằng có một số vấn đề đường dẫn khi gán URL để lưu trữ nhưng vẫn không thể giải quyết. Tệp "gridData.php" của tôi, tệp JS và tệp HTML nơi lưới đang được hiển thị, nằm trong cùng một thư mục và tôi đang ở "localhost/myapp". Hãy giúp tôi!
FYI, tôi sao chép mã của bạn và chạy nó trên ExtJS 3.3.1, và nó chạy như mong đợi. Không tìm thấy lỗi. Một điều tôi sẽ đề nghị là kiểm tra mã PHP của bạn. Đảm bảo rằng JSON trả về là sạch và hợp lệ. Từ những gì tôi thấy JSON có vẻ khó mã hóa theo một cách nào đó. Một số spacings không có vẻ tự nhiên từ 'json_encode'. –