【问题标题】:Trouble with Dojo DgridDojo Dgrid 的问题
【发布时间】:2013-11-08 22:33:02
【问题描述】:

我想用新的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 进行了测试
  • 似乎主要问题在于渲染

感谢您的帮助或建议!

【问题讨论】:

  • “几件事”中的“列出项目”是一个错误:(

标签: javascript datagrid dojo dgrid


【解决方案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();
});

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

【讨论】:

  • 真的很感谢 - 我首先声明了像对象数组一样声明了字段和标签属性的字段(就像你现在建议的那样))但这不起作用(但我在 dgrid 主页上看到了)......您指出的这个变体效果很好......再次感谢。由。
  • 当您将columns 指定为对象时,默认情况下,这些键被重用为field 属性的值,所以我不确定您的原始代码是如何工作的确实如此。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多