fix version select order

This commit is contained in:
afc163 2015-10-19 18:04:54 +08:00
parent f26bbc1cd5
commit 6135242dc3
2 changed files with 8 additions and 5 deletions

View File

@ -89,6 +89,7 @@
"precommit-hook": "^1.0.7",
"react": "~0.13.0",
"react-router": "1.0.0-rc1",
"semver": "~5.0.3",
"webpack": "^1.10.1",
"webpack-dev-middleware": "^1.2.0"
},

View File

@ -4,6 +4,7 @@ var antd = require('antd');
var $ = require('jquery');
var React = require('react');
var semver = require('semver');
InstantClickChangeFns.push(function () {
// auto complete for components
@ -54,18 +55,19 @@ InstantClickChangeFns.push(function () {
};
versionsHistory[antdVersion.latest] =
versionsHistory[antdVersion.latest] || 'http://ant.design';
var options = Object.keys(versionsHistory).map(function(version) {
var versions = Object.keys(versionsHistory).sort(function(a, b) {
return semver.lt(a, b);
});
var options = versions.map(function(version) {
var link = versionsHistory[version];
return <option value={version}>{version}</option>;
});
function onChange(e) {
if (versionsHistory[e.target.value]) {
location.replace(versionsHistory[e.target.value]);
location.href = versionsHistory[e.target.value];
}
}
React.render(<select defaultValue={antdVersion.latest} onChange={onChange}>
{options}
</select>, document.getElementById('versions-select'))
React.render(<select defaultValue={antdVersion.latest} onChange={onChange}>{options}</select>, document.getElementById('versions-select'));
});
module.exports = antd;