【问题标题】:how to get field type from store in Extjs4?如何从 Extjs4 中的商店获取字段类型?
【发布时间】:2011-11-19 09:34:31
【问题描述】:

我不会在 Extjs4 中获取存储字段类型

这段代码在 Extjs 3.3.2 下运行

var f = store.fields.get(id); // store field name in parameter its return object
alert(f.type.type); //its give me data type of that field 

但上面的代码在 Extjs4 中不起作用,它给出了 undefine 的错误

那么如何知道存储字段类型

我的痛是

var data_sample = new Ext.data.SimpleStore({
    fields: [
        {name: 'yr', type: 'string'}
        ,{name: 'sales', type: 'int'}
        ,{name: 'expenses', type: 'int'}
    ],
    data: [['2004',1000,400],['2005',1170,460],['2006',860,580],['2007',1030,540]]
});


var year = store.data.get(0).get('yr'); 
if ( year.constructor == (new Date).constructor){ 
alert("date"); 
}

这给我错误,即浏览器年份为空

【问题讨论】:

    标签: javascript extjs extjs4 javascript-framework


    【解决方案1】:

    您可以像这样访问数据,

    var year = data_sample.data.get(id).get('yr');
    

    我在 store 对象中找不到 type 属性,但是 你可以通过做得到类型,

    var type = typeof year;
    

    您将获得类型编号,而不是获取类型 int。

    仍然保留模型中定义的类型,因为它将数据转换为正确的类型。因此,如果销售数据是“1000”,它将变成 1000

    【讨论】:

    • 我尝试使用日期类型使用 var year = store.data.get(0).get('yr'); if (year.constructor == (new Date).constructor){ alert("date");这给了我错误,即浏览器年份为空。
    猜你喜欢
    • 2013-01-22
    • 2015-05-18
    • 1970-01-01
    • 2014-04-16
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 2011-11-18
    • 2013-04-20
    相关资源
    最近更新 更多