【问题标题】:Parsing variables with dot notation in Extjs在 Extjs 中用点符号解析变量
【发布时间】:2012-03-02 14:00:22
【问题描述】:

当我从 json 解析这些值时,Extjs 的网格中的值变为空,这基本上是因为属性标签带有点。

"properties": {
            "financialYear": "2009",
            "employee.employeeId": "12345",
            "employee.employeeName": "abc"
        }

如何让 .js 中的 employee.employeeId 值显示在 Extjs 网格中。

现在我在 .js 中像这样映射,

Ext.define('DocProperties',{
extend: 'Ext.data.Model',
fields: [
    {name: 'financialYear', type: 'string'},
    {name:'employeeId', mapping:'properties.employee.employeeId',type: 'string'},
]});

为了在网格面板中显示,我正在像这样访问,

{
        width:100,
        header: "Employee ID",
        dataIndex: 'employeeId',
        sortable: true
    } 

任何解决方案或解决方法。


@DmitryB 谢谢,但这并没有解决我的问题,我有这样的商店

Ext.onReady(function() {

var store = Ext.create('Ext.data.Store', {
    model: 'DocResult',
    autoLoad: true,
    proxy: {
        type: 'rest',
        url : 'sample-data.json',
        reader: {
            type: 'json',
            root: 'results',
            useSimpleAccessors: true
        }
    }
});

在我的模型中我是这样定义的

Ext.define('DocResult',{
extend: 'Ext.data.Model',
fields: [
    {name: 'id', type: 'int'},
    {name:'employeeId', mapping:'properties.employee.employeeId',type: 'string'}

] });

然后在我的 Ext 网格中也显示空值。请帮助。

【问题讨论】:

    标签: json extjs extjs4


    【解决方案1】:

    只要查看源代码,您可能会尝试以下操作:

    mapping:'properties["employee.employeeId"]'
    

    useSimpleAccessors 设置为truefalse 一起尝试,然后告诉我结果是什么。

    【讨论】:

    • 嗨 BigSean...非常感谢..它通过将 useSimpleAccessors 设置为 false 并按照您所说的映射来工作..非常感谢!!!!
    【解决方案2】:

    尝试将 useSimpleAccessors 选项设置为 true。默认为假。

    http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Json-cfg-useSimpleAccessors

    编辑:同样基于您在不同答案中提供的 Store 定义,JSON 阅读器配置需要更改为 root: "properties"

    除非您没有提供完整的 JSON 示例并且属性被包装在“结果”对象中,否则您需要设置根:“结果”和记录:“属性”

    【讨论】:

    • 谢谢 DmitryB ..我会在 cmets 中做这件事 ..是的,我使用了 BigSean 建议的 simpleAccessors 属性和映射..它起作用了。
    猜你喜欢
    • 2021-05-12
    • 2012-06-28
    • 2012-09-30
    • 1970-01-01
    • 2023-03-05
    • 2013-07-04
    • 2015-02-17
    • 1970-01-01
    • 2011-05-15
    相关资源
    最近更新 更多