/* * @Description: * @Author: hy * @Date: 2019-08-14 17:41:15 * @LastEditTime: 2019-08-14 17:41:15 */ Ext.define('uas.data.DataList', { requires: [ 'uas.data.Init' ] }, function() { var dataLists = { "total": "27", "data": [{ "id": "1", "price": "71.72", "company": "3m Co", "date": "2007-09-01", "size": "large", "visible": "1" }, { "id": "2", "price": "31.61", "company": "AT&T Inc.", "date": "2008-02-01", "size": "extra large", "visible": "0" }, { "id": "3", "price": "29.01", "company": "Aloca Inc", "date": "2007-08-01", "size": "medium", "visible": "0" }, { "id": "4", "price": "83.81", "company": "Altria Group Inc", "date": "2007-08-03", "size": "large", "visible": "0" }, { "id": "5", "price": "52.55", "company": "American Express Company", "date": "2008-01-04", "size": "extra large", "visible": "1" }, { "id": "6", "price": "64.13", "company": "American International Group Inc.", "date": "2008-03-04", "size": "small", "visible": "1" }, { "id": "7", "price": "75.43", "company": "Boeing Co.", "date": "2008-01-01", "size": "large", "visible": "1" }, { "id": "8", "price": "67.27", "company": "Caterpillar Inc.", "date": "2007-12-03", "size": "medium", "visible": "1" }, { "id": "9", "price": "49.37", "company": "Citigroup, Inc.", "date": "2007-11-24", "size": "large", "visible": "1" }, { "id": "10", "price": "40.48", "company": "E.I. du Pont de Nemours and Company", "date": "2007-05-09", "size": "extra large", "visible": "0" }, { "id": "11", "price": "68.1", "company": "Exxon Mobile Corp", "date": "2007-12-12", "size": "large", "visible": "1" }, { "id": "12", "price": "34.14", "company": "General Electric Company", "date": "2008-06-16", "size": "extra large", "visible": "1" }, { "id": "13", "price": "30.27", "company": "General Motors Corporation", "date": "2006-12-07", "size": "medium", "visible": "1" }, { "id": "14", "price": "36.53", "company": "Hewlett-Packard Co.", "date": "2007-05-13", "size": "large", "visible": "1" }, { "id": "15", "price": "38.77", "company": "Honweywell Intl Inc", "date": "2006-11-07", "size": "medium", "visible": "0" }, { "id": "16", "price": "19.88", "company": "Intel Corporation", "date": "2007-01-09", "size": "small", "visible": "1" }, { "id": "17", "price": "81.41", "company": "International Business Machines", "date": "2005-01-21", "size": "extra large", "visible": "1" }, { "id": "18", "price": "64.72", "company": "Johnson & Johnson", "date": "2008-01-10", "size": "extra large", "visible": "1" }, { "id": "19", "price": "45.73", "company": "JP Morgan & Chase & Co", "date": "2008-02-20", "size": "large", "visible": "0" }, { "id": "20", "price": "36.76", "company": "McDonald's Corporation", "date": "2007-06-12", "size": "large", "visible": "1" }, { "id": "21", "price": "27.96", "company": "Pfizer Inc", "date": "2007-12-30", "size": "small", "visible": "0" }, { "id": "22", "price": "45.07", "company": "The Coca-Cola Company", "date": "2007-01-30", "size": "medium", "visible": "0" }, { "id": "23", "price": "34.64", "company": "The Home Depot, Inc", "date": "2006-12-31", "size": "small", "visible": "1" }, { "id": "24", "price": "61.91", "company": "The Procter & Gamble Company", "date": "2007-04-08", "size": "extra large", "visible": "1" }, { "id": "25", "price": "63.26", "company": "United Technologies Corporation", "date": "2006-06-04", "size": "medium", "visible": "1" }, { "id": "26", "price": "35.57", "company": "Verizon Communications", "date": "2005-07-09", "size": "small", "visible": "0" }, { "id": "27", "price": "45.45", "company": "Wal-Mart Stores, Inc", "date": "2006-09-09", "size": "large", "visible": "1" }] }; //from https://git.daplie.com/Daplie/knuth-shuffle/ function shuffle (array) { array = Ext.Array.clone(array); var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } Ext.ux.ajax.SimManager.register({ type: 'json', delay: 300, url: /\/uas\/DataList(\/\d+)?/, data: function(ctx) { var idPart = ctx.url.match(this.url)[1], id; if (idPart) { id = parseInt(idPart.substring(1), 10); return Ext.Array.findBy(dataLists, function(dataList) { return dataList.id === id; }); } else if (ctx.params.shuffle) { return shuffle(dataLists); } return dataLists; } }); });