我知道这个问题应该设置idProperty config。
就我而言,我有两个元数据。一个具有每个数据的唯一ID,但另一个具有相同的ID。
当我按下A按钮它工作正常并加载每个数据时,按B按钮它只加载一行。
我尝试为两个视图设置属性,但没有工作。
有人帮我解决这个问题吗?谢谢! Fiddle
app.js
Ext.application({
name: 'Fiddle',
appFolder: 'app',
autoCreateViewport: true,
//stores: ['ListViewStore'],
controllers: ['ListViewController'],
launch: function() {
}
});
视口
Ext.define('Fiddle.view.Viewport', {
extend: 'Ext.container.Viewport',
layout: 'border',
requires: ['Fiddle.view.ListView', 'Fiddle.view.ButtonA', 'Fiddle.view.ButtonB'],
items: [{
region: 'north',
xtype: 'toolbar',
items: [{
xtype: 'btna'
}, {
xtype: 'btnb'
}]
}, {
region: 'center',
xtype: 'listview',
}]
});
视图
Ext.define('Fiddle.view.ListView', {
extend: 'Ext.grid.Panel',
alias: 'widget.listview',
title: 'MVC Grid Sample',
store: 'ListViewStore',
height: 200,
width: 400,
initComponent: function() {
var me = this;
me.columns = [{
header: 'track',
dataIndex: 'track',
flex: 1
}, {
header: 'title',
dataIndex: 'title',
flex: 1
}, {
header: 'album',
dataIndex: 'album',
flex: 1
}, {
header: 'length',
dataIndex: 'duration',
flex: 1
}, {
header: 'artist',
dataIndex: 'artist',
flex: 1
}, {
header: 'type',
dataIndex: 'genre',
flex: 1
}, {
header: 'rank',
dataIndex: 'rank',
flex: 1
}];
me.callParent(arguments);
}
});
模型
Ext.define('Fiddle.model.ListViewModel', {
extend: 'Ext.data.Model',
fields: ['track', 'title', 'album', 'duration', 'artist', 'rank', 'path', 'artwork', 'id', 'genre', 'album_artist', 'click_counting', 'last_play', 'amount', 'valuetype']
});
存储
Ext.define('Fiddle.store.ListViewStore', {
extend: 'Ext.data.Store',
model: 'Fiddle.model.ListViewModel',
loadByBuffer: function(data) {
var store = this;
var newData = [];
Ext.each(data, function(item) {
newData.push([
item['track'],
// item['title'],
(function() {
if (item['valuetype'] === 3) {
if (item['album'] == '') {
return 'Unknown Album';
} else {
return item['album'];
}
} else if (item['valuetype'] === 1) {
if (item['artist'] == '') {
return 'Unknown Artist';
} else {
return item['artist'];
}
} else {
return item['title'];
}
})(),
item['album'],
item['duration'],
item['artist'],
// item['valuetype'],
item['rank'],
item['path'],
item['artwork'],
item['id'],
item['genre'],
item['album_artist'],
item['click_counting'],
item['last_play'],
item['amount'],
item['valuetype'], ]);
});
store.loadData(newData, true);
}
});
控制器
Ext.define('Fiddle.controller.ListViewController', {
extend: 'Ext.app.Controller',
stores: ['ListViewStore'],
init: function() {
var me = this;
me.control({
'btna': {
toggle: me.clickButtonA
},
'btnb': {
toggle: me.clickButtonB
},
});
me.clickButtonA(this, true);
},
clickButtonA: function(me, pressed) {
var me = this;
if (pressed !== true) {
return;
}
var data = [{
"valuetype": 4,
"id": 81,
"amount": -1,
"duration": 290,
"track": 14,
"rank": 0,
"click_counting": 0,
"last_play": 0,
"title": "Come Together",
"path": "\/volume1\/Music\/Aerosmith - Rocks Donington 2014\/CD2\/04 Come Together.mp3",
"genre": "79",
"album_artist": "",
"artist": "Aerosmith",
"album": "Rocks Donington",
"artwork": ""
}, {
"valuetype": 4,
"id": 90,
"amount": -1,
"duration": 231,
"track": 0,
"rank": 0,
"click_counting": 0,
"last_play": 0,
"title": "Freedom Fighter",
"path": "\/volume1\/Music\/Aerosmith - Rocks Donington 2014\/CD1\/08 Freedom Fighter.mp3",
"genre": "79",
"album_artist": "",
"artist": "Aerosmith",
"album": "Rocks Donington",
"artwork": ""
}, {
"valuetype": 4,
"id": 117,
"amount": -1,
"duration": 199,
"track": 0,
"rank": 0,
"click_counting": 0,
"last_play": 0,
"title": "Lord Don't Slow Me Down",
"path": "\/volume1\/Music\/Oasis - Time Flies Greatest Hits 2CD [Bubanee]\/CD1\/11 - Lord Don't Slow Me Down.mp3",
"genre": "Pop",
"album_artist": "",
"artist": "Oasis",
"album": "Time Flies... 1994-2009 CD1",
"artwork": "\/volume1\/Music\/Oasis - Time Flies Greatest Hits 2CD [Bubanee]\/CD1\/11 - Lord Don't Slow Me Down.mp3"
}];
me.getListViewStoreStore().removeAll();
me.getListViewStoreStore().loadByBuffer(data);
},
clickButtonB: function(me, pressed) {
var me = this;
if (pressed !== true) {
return;
}
var data = [{
"valuetype": 3,
"id": -1,
"amount": 20,
"duration": -1,
"track": -1,
"rank": -1,
"click_counting": -1,
"last_play": -1,
"title": "",
"path": "",
"genre": "",
"album_artist": "",
"artist": "Aerosmith",
"album": "Rocks Donington",
"artwork": ""
}, {
"valuetype": 3,
"id": -1,
"amount": 13,
"duration": -1,
"track": -1,
"rank": -1,
"click_counting": -1,
"last_play": -1,
"title": "",
"path": "",
"genre": "",
"album_artist": "",
"artist": "Oasis",
"album": "Time Flies... 1994-2009 CD1",
"artwork": "\/volume1\/Music\/Oasis - Time Flies Greatest Hits 2CD [Bubanee]\/CD1\/05 - Stop Crying Your Heart Out.mp3"
}, {
"valuetype": 3,
"id": -1,
"amount": 14,
"duration": -1,
"track": -1,
"rank": -1,
"click_counting": -1,
"last_play": -1,
"title": "",
"path": "",
"genre": "",
"album_artist": "",
"artist": "Oasis",
"album": "Time Flies... 1994-2009 CD2",
"artwork": "\/volume1\/Music\/Oasis - Time Flies Greatest Hits 2CD [Bubanee]\/CD2\/04 - D'You Know What I Mean¿.mp3"
}];
me.getListViewStoreStore().removeAll();
me.getListViewStoreStore().loadByBuffer(data);
}
});