Yoji SHIDARA
null+****@clear*****
Tue Oct 16 11:30:53 JST 2012
Yoji SHIDARA 2012-10-16 11:30:53 +0900 (Tue, 16 Oct 2012) New Revision: f016e1a2515d0862d305d1d15c5d663a6302aa86 https://github.com/groonga/gcs-console/commit/f016e1a2515d0862d305d1d15c5d663a6302aa86 Log: Add a helper function to return array always Modified files: routes/index.js Modified: routes/index.js (+13 -1) =================================================================== --- routes/index.js 2012-10-15 16:17:20 +0900 (6a20568) +++ routes/index.js 2012-10-16 11:30:53 +0900 (691ec6c) @@ -12,6 +12,18 @@ function prepareCurrentDomain(req, res) { return domain; } +function convertToArray(data) { + // awssum returns undefined for 0 item, object itself for 1 item, + // array for >1 items. Make all of them as a Array. + if (!data) { + return []; + } else if (!(data instanceof Array)) { + return [data]; + } else { + return data; + } +} + exports.domain = function(req, res) { var domain = prepareCurrentDomain(req, res); res.render('domain-show', {domain: domain}); @@ -31,7 +43,7 @@ exports.domainSearch = function(req, res) { res.render('error', {message: error.Message}); return; } - var indexFields = data.Body.DescribeIndexFieldsResponse.DescribeIndexFieldsResult.IndexFields.member; + var indexFields = convertToArray(data.Body.DescribeIndexFieldsResponse.DescribeIndexFieldsResult.IndexFields.member); var indexFieldNames = indexFields.map(function(indexField) { return indexField.Options.IndexFieldName; }); -------------- next part -------------- HTML����������������������������...Download