0

我有与另一个模型Chamber相关联的模型Schedule。当关联的模型数据为空时,我遇到了问题。这是正常行为,因为它不是必填字段。

升级调度模型是 scheduleTree 模型的一部分,用于存储从服务器加载数据。

Ext.define('...SchedulesTree', {
    extend : '...TreeStore',
    model: "...ScheduleTree",
    root: {
        expanded: true,
        text: "root",
        children: [],
        loaded: true
    },
    paramsAsHash : true,
    proxy : {
        type: "direct",
        autoLoad: false,
        api : {
            read: registratorAction.getScheduleNode
        },
        reader: {
            type: "json",
            root : "records",
            totalProperty: 'total'
       }
    }
});

Ext.define("...ScheduleTree", {
    extend: "Ext.data.Model",


...
    associations: [   
        {
            type: "hasMany",
            model: "Unimed.model.staff.Schedule",
            name: "schedules",
            getterName: "schedules"
        }
    ]
});


Ext.define("...Schedule", {
extend: "Ext.data.Model",
fields: [
    {name: "timeBegin", type: "date", dateFormat: "time"},
    {name: "timeEnd", type: "date", dateFormat: "time"}
],
proxy: {
    type: "direct",
    reader: {
        type: "json"
    }
},
associations: [
    {
        type: "belongsTo",      
        model: "..LpuPosition", 
        associationKey: "lpuPosition",
        getterName: "lpuPosition",
        associatedName: "lpuPosition"
    },
    {
        type: "belongsTo",
        model: "...Chamber",
        associationKey: "chamber",
        getterName: "chamber",
        associatedName: "chamber"
    }
]
});

当我得到房间时:

chamber = schedule.chamber();

并且没有链接数据我得到异常:'Uncaught TypeError:undefined is not a function'。

我可以通过查看原始数据来解决问题,但可能存在更优雅的解决方案吗?

4

0 回答 0