gpt4 book ai didi

sencha-touch-2 - 在app.js中引用商店?

转载 作者:行者123 更新时间:2023-12-03 22:45:14 26 4
gpt4 key购买 nike

我创建了一个模型并存储,并在其中读取了一个json文件,如下所示。如何在app.js中引用此商店?

我想以Sencha提供here的搜索列表为例。

并在示例中将商店用作此行的替代品:

store = this.getStore();


[更新]添加了重新格式化的 app.js here


模型:


Ext.define('Sencha.model.Contact', {
extend: 'Ext.data.Model',

config: {
fields: [{
name: 'firstName',
type: 'string'
}, {
name: 'lastName',
type: 'string'
}]
}
});



商店:


Ext.define('Sencha.store.Contacts', {
extend: 'Ext.data.Store',
config: {
model: 'Sencha.model.Contact',
sorters: 'firstName',
autoLoad: true,

grouper: {
groupFn: function(record) {
return record.get('firstName')[0];
}
},
proxy: {
type: 'ajax',
url: 'contacts.json'
}
}
});



格式:app.js


Ext.application({
phoneStartupScreen: "resources/loading/Homescreen.jpg",
tabletStartupScreen: "resources/loading/Homescreen~ipad.jpg",
glossOnIcon: false,
icon: {
57: "resources/icons/icon.png",
72: "resources/icons/icon@72.png",
114: "resources/icons/icon@2x.png",
144: "resources/icons/icon@114.png"
},
requires: ["Ext.data.Store", "Ext.List", "Ext.field.Search", "Ext.Toolbar"],
launch: function() {
var a = this.getListConfiguration();
if (!Ext.os.is.Phone) {
Ext.Viewport.add({
xtype: "panel",
width: 380,
height: 420,
centered: true,
modal: true,
hideOnMaskTap: false,
layout: "fit",
items: [a]
}).show()
} else {
Ext.Viewport.add(a)
}
},
getListConfiguration: function() {
return {
xtype: "list",
ui: "round",
pinHeaders: false,
itemTpl: '<div class="contact">{firstName} <strong>{lastName}</strong></div>',
store: this.getStore(),
grouped: true,
emptyText: '<div style="margin-top: 20px; text-align: center">No Matching Items</div>',
disableSelection: true,
items: [{
xtype: "toolbar",
docked: "top",
items: [{
xtype: "spacer"
}, {
xtype: "searchfield",
placeHolder: "Search...",
listeners: {
scope: this,
clearicontap: this.onSearchClearIconTap,
keyup: this.onSearchKeyUp
}
}, {
xtype: "spacer"
}]
}]
}
},
getStore: function() {
if (!this.store) {
this.store = Ext.create("Ext.data.Store", {
fields: ["firstName", "lastName"],
sorters: "lastName",
groupField: "lastName",
data: [{
firstName: "Tommy",
lastName: "Maintz"
}, {
firstName: "Rob",
lastName: "Dougan"
}, {
firstName: "Ed",
lastName: "Avins"
}, {
firstName: "Jamie",
lastName: "Avins"
}, {
firstName: "Dave",
lastName: "Dougan"
}, {
firstName: "Abraham",
lastName: "Elias"
}, {
firstName: "Jacky",
lastName: "Ngyuyen"
}, {
firstName: "Jay",
lastName: "Ngyuyen"
}, {
firstName: "Jay",
lastName: "Robinson"
}, {
firstName: "Rob",
lastName: "Avins"
}, {
firstName: "Ed",
lastName: "Dougan"
}, {
firstName: "Jamie",
lastName: "Poulden"
}, {
firstName: "Dave",
lastName: "Spencer"
}, {
firstName: "Abraham",
lastName: "Avins"
}, {
firstName: "Jacky",
lastName: "Avins"
}, {
firstName: "Rob",
lastName: "Kaneda"
}, {
firstName: "Ed",
lastName: "Elias"
}, {
firstName: "Tommy",
lastName: "Dougan"
}, {
firstName: "Rob",
lastName: "Robinson"
}]
})
}
return this.store
},
onSearchKeyUp: function(f) {
var e = f.getValue(),
b = this.getStore();
b.clearFilter();
if (e) {
var d = e.split(" "),
a = [],
c;
for (c = 0; c < d.length; c++) {
if (!d[c]) {
continue
}
a.push(new RegExp(d[c], "i"))
}
b.filter(function(h) {
var g = [];
for (c = 0; c < a.length; c++) {
var j = a[c],
i = h.get("firstName").match(j) || h.get("lastName").match(j);
g.push(i)
}
if (a.length > 1 && g.indexOf(false) != -1) {
return false
} else {
return g[0]
}
})
}
},
onSearchClearIconTap: function() {
this.getStore().clearFilter()
}
});

最佳答案

最简单的方法是为您的商店设置ID,并在以后使用

Ext.getStore('your-store-id');

PS:如果为此获得undefined,则应首先创建商店,如下所示:

store = Ext.create('Sencha.store.Contacts');

关于sencha-touch-2 - 在app.js中引用商店?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10090369/

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