0

我想用新的Dgrid替换dojox.grid.DataGrid但我遇到了麻烦。我正在使用 Dojo 1.9.1,这是我的代码摘录:

HTML:

<script type="text/javascript"><!--
require({
    baseUrl: "/res/js/",
    packages: [
        { name: "dojo", location: "dojo/dojo" },
        { name: "dijit", location: "dojo/dijit" },
        { name: "dojox", location: "dojo/dojox" },
        { name: "put-selector", location: "put-selector" },
        { name: "xstyle", location: "xstyle" },
        { name: "dgrid", location: "dgrid" },
        { name: "allwins", location: "allwins" }
    ]
},[
    "allwins/Admin",
    "dojo/parser",
    "dojo/domReady!"
],function(admin, Parser){
    admin.initUi(/*...*/);
});
</script>
<!-- ... -->
<div data-dojo-id="invoicesTab2" 
     data-dojo-type="dijit.layout.BorderContainer" 
     data-dojo-props="region: 'center',
                      title: 'Faktury 2'">
    <div id=invoicesGridTab2"></div>
</div>

JavaScript:

request(invoicesDataUrl, { 
    handleAs: "json" 
}).then(function (response) {
    var store = new Memory({ data: response });
    var grid = new OnDemandGrid({
        region: "center",
        store: store,
        columns: {
            invoice_id: { label: "FID" },
            user_id: { label: "UID" },
            invoice_no: { label: "Číslo" },
            user_fullname: { label: "Plátce" },
            created_formatted: { label: "Vystavena" },
            payment_date_formatted: { label: "Splatnost" },
            payment_total: { label: "Částka" }
        }
    }, "invoicesGridTab2");
    grid.startup();
});

我可以添加更多内容:

  • 项目清单
  • 我在 JavaScript 控制台上没有错误
  • 数据源已经使用较旧的 dojox.grid.DataGrid 进行了测试
  • 似乎主要问题在于渲染

感谢您的任何帮助或建议!

4

1 回答 1

1

您需要在与响应数据对象匹配的列中指定字段属性,例如:

request(invoicesDataUrl, { 
    handleAs: "json" 
}).then(function (response) {
    var store = new Memory({ data: response });
    var grid = new OnDemandGrid({
        region: "center",
        store: store,
        columns: {
            invoice_id: { label: "FID", field: "invoice_id" },
            user_id: { label: "UID", field: "user_id" },
            invoice_no: { label: "Číslo", field: "invoice_no" },
            user_fullname: { label: "Plátce", field: "user_fullname" },
            created_formatted: { label: "Vystavena", field: "created_formatted" },
            payment_date_formatted: { label: "Splatnost", field: "payment_date_formatted" },
            payment_total: { label: "Částka", field: "payment_total" }
        }
    }, "invoicesGridTab2");
    grid.startup();
});

我不知道这些字段名称是否正确,但我想你会的。:)

于 2013-10-29T18:49:55.177 回答