gpt4 book ai didi

javascript - 什么是数据类型以及如何初始化它?

转载 作者:行者123 更新时间:2023-11-29 22:35:38 25 4
gpt4 key购买 nike

    
demos.ListStore = new Ext.data.Store({
model: 'Contact',
sorters: 'firstName',
getGroupString : function(record) {
return record.get('firstName')[0];
},

data: [
{firstName: 'Julio', lastName: 'Benesh'},
{firstName: 'Julio', lastName: 'Minich'},
{firstName: 'Tania', lastName: 'Ricco'},
{firstName: 'Odessa', lastName: 'Steuck'},
{firstName: 'Nelson', lastName: 'Raber'},
{firstName: 'Tyrone', lastName: 'Scannell'},
{firstName: 'Allan', lastName: 'Disbrow'},
{firstName: 'Cody', lastName: 'Herrell'},
{firstName: 'Julio', lastName: 'Burgoyne'},
{firstName: 'Jessie', lastName: 'Boedeker'},
{firstName: 'Allan', lastName: 'Leyendecker'},
{firstName: 'Javier', lastName: 'Lockley'},
{firstName: 'Guy', lastName: 'Reasor'},
...,
...
]
})

在我的理解中,“数据”不是 javascript 的字典或数组类型。jQuery 是否额外支持这种数据类型?

我的问题是:

  1. Ext.data.Store(...) 的参数类型是什么?

  2. 还有,数据的类型?

  3. 在这种情况下,如何动态初始化数据?
    (我有很多数据,所以静态赋值是不可取的。)

非常感谢!

最佳答案

1) What is the type of parameter of Ext.data.Store(...)?

它只是一个普通对象,带有一堆用作关联数组的属性。几乎所有 Ext JS 中的函数参数都是使用像这样的单个对象传入的。在 Ext JS 术语中,他们称之为“配置对象”。

2) Also, the type of data?

数据是一个数组。数组的每个元素都是一个对象,有一堆属性用作关联数组,类似于Ext.data.Store()的参数。

3) In this case, how can I dynamically init the data?

您可以声明一个空数组来启动并将其添加到您的配置对象中。然后分别声明每一行并将它们压入该数组,最后在调用 new Ext.data.Store() 时使用配置对象。

希望这些代码示例不言自明。

var cfg = new Object(); // same as var cfg = {};
cfg.model = "Contact"; // one way to set a property
cfg["sorters"] = "firstName"; // another way to set a property

// one way to set the function
cfg.getGroupString = function(record) {
return record.get('firstName')[0];
};

// here's another way to set the function
function myGetGroupString(record) {
return record.get('firstName')[0];
}
cfg.getGroupString = myGetGroupString;

// initializing data long-hand
cfg.data = new Array(); // same as cfg.data = [];
var record1 = new Object();
record1.firstName = "Mike";
record1.lastName = "Lin";
cfg.data.push(record1);

// another way to define a record
var record2 = {firstName: "Jason", lastName: "Mraz"};
cfg.data.push(record2);

// cfg is just a plain old object used as an associative array/hash
demos.ListStore = new Ext.data.Store(cfg);

关于javascript - 什么是数据类型以及如何初始化它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5202622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com