admin管理员组文章数量:1292116
I can't seem to get the months to show properly, October always es after January because its value is 10... which I am assuming somehow in some sorting is less than 2. Here is the fiddle for the code:
/
<select ng-model="month" ng-options="key as value for (key,value) in months"></select>
I had the same issue with countries where I couldn't get USA to appear as second entry as it would do its own crazy sorting.
Any help appreciated.
I can't seem to get the months to show properly, October always es after January because its value is 10... which I am assuming somehow in some sorting is less than 2. Here is the fiddle for the code:
http://jsfiddle/naZQA/
<select ng-model="month" ng-options="key as value for (key,value) in months"></select>
I had the same issue with countries where I couldn't get USA to appear as second entry as it would do its own crazy sorting.
Any help appreciated.
Share asked Mar 22, 2013 at 21:44 agrublevagrublev 7681 gold badge8 silver badges22 bronze badges3 Answers
Reset to default 6Using ng-options with an object is just iterating over the object properties which aren't guaranteed to be in any order. If you can change it to be an array, they are guaranteed to be in the order specified. Updated fiddle. Then the select looks like this:
<select ng-model="month" ng-options="currMonth for currMonth in months"></select>
If you needed to keep the same values for the ng-model, you can also have an array of key/value pairs. See this fiddle Then the select looks like this:
<select ng-model="month" ng-options="currMonth.key as currMonth.value for currMonth in months"></select>
It was discussed in this question here . And hence angular does not allow to use orderBy
with simple hashes, you are not able to proceed with sorting without restructuring your data.
Here's a fiddle with changed data structure fiddle
Update: updated link to fiddle
Try this workaround I mented in AngularJS select docs.
Use months.indexOf(m) as the select value.
<select ng-model="monthIndex" ng-options="months.indexOf(m) as m for m in months"></select>
This way you can use a simple string array as the source and have ng-model updated with the selected index.
Try it here: jsbin
本文标签: javascriptAngularJS can39t get months dropdown to display in orderStack Overflow
版权声明:本文标题:javascript - AngularJS can't get months dropdown to display in order - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741547639a2384688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论