简体   繁体   English

JavaScript / AngularJS:将数组值转换为Integer

[英]JavaScript/AngularJS: converting array value to Integer

Can't seem to find an answer for this. 似乎找不到答案。 I have a select box which when clicked on maps to my model - 我有一个选择框,当单击它映射到我的模型时,

<select class="form-control"
        size="8"
        ng-model="Info.FolderId"
        ng-options="Folder.Id as Folder.Name for Folder in AvailableFolders">
</select> 

So the model holds the Id of the folder. 因此,模型保存文件夹的ID。 However that Id will not be stored as "1" or "2" it will be stored as [1] or [2]. 但是,该ID将不会存储为“ 1”或“ 2”,而是将其存储为[1]或[2]。

Is there an easy way of converting this using something like ng-change, or an easier way I should be going about doing this? 有没有简单的方法可以使用ng-change之类的方法进行转换,还是我应该执行的更简单的方法?

Try this. 尝试这个。

<select class="form-control"
        size="8"
        ng-model="Info.FolderId"
        ng-options="Folder.Id[0] as Folder.Name for Folder in AvailableFolders">
</select> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM