1
我正在使用jqGrid來顯示JavaScript對象的數組。我想要顯示的其中一個值是對象的函數,而不是屬性。在下面的例子中,所有的值都是除'timeliness()'之外的屬性,它是計算交貨和到期日之間的差異並返回一個及時性值的函數。任何方式來使用對象的函數作爲jqGrid數據數組的值?
$("#list").jqGrid({
datatype: 'local',
data: assignments,
colNames: ['Project', 'Date Due', 'Date Delivered', "Timeliness"],
colModel: [
{name: 'project.title', index: 'project.title', width: 100},
{name: 'title', index: 'title', width: 250},
{name: 'dueDate',index: 'dueDate', width: 100},
{name: 'deliveryDate', index: 'deliveryDate', width: 100},
{name: 'timeliness()', index: 'timeliness()', width: 100}
],
sortname: 'Project',
rowNum: 10000,
sortorder: 'asc',
viewrecords: true,
loadonce: true,
gridview: true,
height: 'auto',
caption: 'Projects'
});
我試過了,如圖所示,函數沒有被調用,也沒有返回值。我試過沒有括號(例如名稱:及時性),並按預期返回函數定義。
使用格式化工程,但它使我無法在列上排序(這是用戶想要排序的列)。另一種解決問題的方法是簡單地爲這個對象創建一個新的屬性,然後在將其傳遞到要顯示的網格之前將其設置在所有對象上(一次在網格中,我不希望這些值改變)。只是有興趣學習,如果這可能在jqGrid中,也許我只是沒有正確處理這個領域。