Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc extjs+中的递归数据结构;春季MVC_Spring Mvc_Extjs_Jackson - Fatal编程技术网

Spring mvc extjs+中的递归数据结构;春季MVC

Spring mvc extjs+中的递归数据结构;春季MVC,spring-mvc,extjs,jackson,Spring Mvc,Extjs,Jackson,我正在SpringMVC和ExtJS4.1中设计一个简单的用户地址簿。我已经用Java定义了我的用户类,以允许引用其他用户: @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id") public class User { @JsonProperty private String name; @JsonProperty private S

我正在SpringMVC和ExtJS4.1中设计一个简单的用户地址簿。我已经用Java定义了我的用户类,以允许引用其他用户:

@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
public class User {

    @JsonProperty
    private String name;

    @JsonProperty
    private String email;

    @JsonProperty
    private List<User> friends = new ArrayList<User>();
}
这里约翰有@ID1,彼得有@ID2。彼得被定义为约翰的朋友,反之亦然。
“total”
前面的2是对Peter的引用,因为他已经被定义了。我的问题是:既然我已经从Jackson那里得到了递归数据结构,那么如何将它们与ExtJS集成呢?我在
models/User.js

Ext.define('AM.model.User', {
    extend : 'Ext.data.Model',
    fields : [ '@id', 'name', 'email' ],
    idProperty : '@id',
    hasMany : [ {
        model : 'AM.model.User',
        name : 'friends',
        associationKey:'friends'
    } ]
});
我能读懂John fine和John.friends中的Peter,但我不能从
数据中读懂Peter,因为所有Ext JS都是
2
(Peter的
@id
)。我在一个房间里展示它们,只有约翰出现了。彼得的那一排是空的

我是否需要覆盖我的JSOG库中的读写器: JSOG JACKSON模块:

您可以使用JSOG库+jackson JSOG模块来实现这一点。 创建自定义读取器,如:

Ext.define('Ext.data.reader.Jsog', {
extend: 'Ext.data.reader.Json',
alternateClassName: 'Ext.data.JsogReader',
alias : 'reader.jsog',

getResponseData: function(response) {
    var data, error;
    try {
        data = JSOG.decode(Ext.decode(response.responseText));
        return this.readRecords(data);
    } catch (ex) {
        error = new Ext.data.ResultSet({
            total  : 0,
            count  : 0,
            records: [],
            success: false,
            message: ex.message
        });

        this.fireEvent('exception', this, response, error);

        Ext.Logger.warn('Unable to parse the JSON returned by the server');

        return error;
    }
}});
商店的定义是

  var store = Ext.create('Ext.data.Store', {
        proxy: {
                        type: 'ajax',
                        reader: 'jsog',
                        url: 'dummydata/data-grid.js'
        },fields: [
            { name: 'company' },
            { name: 'price', type: 'float' },
            { name: 'change', type: 'float' },
            { name: 'pctChange', type: 'float' },
            { name: 'lastChange', type: 'date', dateFormat: 'n/j h:ia' }
        ]
    });
读者请参考我们实施的解决方案

dummydata

[
{ "@id": "1",  "company" : "a" , "price" : 2},
{ "@id": "2",  'company' : "b" },
{ "@id": "3",  "company" : "c" },
{ "@id": "4",  "company" : "d" },
{ '@ref': "1" },
{ "@ref": "3" },
{ "@ref": "2" },
{ "@ref": "4" }]

我注意到我有一个与你基本相同的问题,你看:你找到了解决这个问题的好方法吗?谢谢哈哈,目前还没有。我已经决定在弄清楚它们是如何工作之前不使用关联。哈哈,看来我需要自己来弄清楚,因为我是extJS:P的新手。我在短期工作中需要这个,所以我准备好后会告诉你:)是的,好的,我在同一条船上,如果我有什么想法,我会让你知道的。为此干杯,自从去年写这篇文章以来,我还没有做过ExtJS,但希望它能对某些人有用
[
{ "@id": "1",  "company" : "a" , "price" : 2},
{ "@id": "2",  'company' : "b" },
{ "@id": "3",  "company" : "c" },
{ "@id": "4",  "company" : "d" },
{ '@ref': "1" },
{ "@ref": "3" },
{ "@ref": "2" },
{ "@ref": "4" }]