0

我一直在尝试通过 json 调用正确填充 yui3 数据表,但未成功。我很困惑,希望有人能告诉我我的方式的错误。无论我尝试了什么,我都会得到“没有数据显示”。

当我在页面加载期间运行 wireshark 时,我看到了从 ajax 调用返回的 json 数据。所以我认为我将数据源正确绑定到数据表。请注意,我感兴趣的数据记录嵌套在元数据中,看来我的 DataSourceJSONSchema 定义是正确的。

这是来自 ajax 调用的 http 响应。

YUI.Env.DataSource.callbacks.yui_3_6_0_1_1346868215546_114({
"recordsReturned":4,"startIndex":0,"dir":"asc","pageSize":10,
"records":[
  {"id":"48ee0540-ebd7-11e1-33e-c33ce39c9e", "email":"jim@example.com","name":"James"},
  {"id":"1447ea60-eca2-11e1-33e-f6c33ce39c9e", "email":"john@example.com","name":"John"},
  {"id":"48ff6a60-ebd7-11e1-a33e-f6c33ce39c9e", "email":"ryan@example.com","name":"Ryan"},
  {"id":"1a298060-f774-11e1-ad38-f6c33ce39c9e", "email":"vincent@example.com","name":"Vince"}]})

这是html页面。

<script type="text/javascript">
YUI({
lang : "en-US"
})
.use("datatable","datatype","datasource",function(Y) {
var ajaxData;
function ajaxSuccess(e) {
ajaxData = e.data;
}
}
function ajaxFailure(e) {
    Y.log("failure");
}

var myDataSource = new Y.DataSource.Get({
    source : "/actions/User.action?getAjaxUserList=&"
});

myDataSource.plug(Y.Plugin.DataSourceJSONSchema,{
    schema : {
        metaFields : {
            recordsReturned : "recordsReturned",
            startIndex : "startIndex",
            dir : "dir",
            pageSize : "pageSize"
        },
        resultsListLocator : "records",
        resultFields : [ {
        key : 'id'}, {
        key : 'email'},{
        key : 'name' }}});

    var table = new Y.DataTable({
    columns : [ {
    key : "id",
    label : "ID"
    }, {
    key : "name",
    label : "Name"}, {
    key : "email",
    label : "Email"} ],
    caption : "My first DataTable!",
    summary : "Example DataTable showing basic instantiation configuration"
                                    });
    table.plug(Y.Plugin.DataTableDataSource, {datasource : myDataSource});

    table.render('#dynamicdata');
    table.datasource.load({request : encodeURIComponent('fred=steve')});
                        });
    </script>

    <div id="dynamicdata"></div>
4

1 回答 1

2

我注意到您在此处提供的代码有几个语法错误:例如,函数(Y)回调关闭得太快。

I think your error is due to the fact that you set in the schema of your Datasource the property "resultsListLocator" instead of "resultListLocator".

于 2012-09-07T20:20:28.273 回答