0
json 스토어에서 데이터를로드하고 화면에 그려주는 간단한 앱을 만들었습니다. 내가 할 수 있기를 원하는 것은 클라이언트 측 저장소에 추가하는 것입니다 (원본 데이터를 제어하지 않습니다). 따라서 저장소로드 : funciton() 또는 MainController에서 너무 늦지 않았다면 시작 부분에 몇 개의 행을 삽입하여 앞에 John, Paul, George 및 Ringo가 표시되도록합니다. 코드 완성을 위해 모든 자바 스크립트를 포함했습니다.저장소가로드 된 직후 저장소에 데이터를 삽입 하시겠습니까?
EmployeeModel :
Ext.define('Sencha.model.Employee', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'},
{
name: 'fullName',
type: 'string',
convert: function (value, record) {
firstName = record.data.firstName;
lastName = record.data.lastName;
fullName = firstName + " " + lastName;
return fullName;
}
}
]
},
load: function() {
console.log("Employee model");
this.callParent(arguments);
}
});
EmployeeStore :
Ext.define('Sencha.store.EmployeeStore', {
extend: 'Ext.data.Store',
requires: [],
config: {
model: 'Sencha.model.Employee',
autoLoad: true,
defaultRootProperty: 'items',
proxy: {
type: 'ajax',
url: 'employees.json',
reader: {
type: 'json',
rootProperty: 'items'
}
}
},
load: function() {
console.log("EmployeeStore");
this.callParent(arguments);
}
});
컨트롤러 : (가게를 얻고 값을 인쇄 할)
Ext.define('Sencha.controller.MainController', {
extend: 'Ext.app.Controller',
requires: [],
config: {
},
launch: function() {
console.log("Main Controller...");
var empStore = Ext.getStore('EmployeeStore');
console.log(empStore.length);
empStore.each(function (val) { // Not working
var firstName = val.get('firstName');
console.log(firstName);
});
}
});
app.js :
Ext.Loader.setConfig({enabled: true});
Ext.application({
name: "Sencha",
models: ['Employee'],
stores: ['EmployeeStore'],
views: [],
controllers: ['MainController'],
launch: function() {
console.log("Launching");
var aList = Ext.create("Ext.List", {
fullscreen: true,
store: 'EmployeeStore',
itemTpl: "{lastName}, {firstName} - {fullName}"
});
Ext.Viewport.add(aList);
}
});
employees.json :
{"items": [
{ "firstName": "John", "lastName": "Lennon" },
{ "firstName": "Paul", "lastName": "McCartney" },
{ "firstName": "George", "lastName": "Harrison" },
{ "firstName": "Ringo", "lastName": "Starr" }
]}