gpt4 book ai didi

angularjs - ng-select 只给出字符串,但我想要一个整数

转载 作者:行者123 更新时间:2023-12-03 07:35:34 25 4
gpt4 key购买 nike

这是我的 Angular html 文件代码。在我的 mongo 数据库中,FrequencyType 添加为 FrequencyType = "1",但我想要 FrequencyType = NumberInt(1);

<div class="span4">
<select class="span12 combobox" ng-model="frequencyType" required>
<option value="1">Daily</option>
<option value="2">Weekly</option>
<option value="3">Monthly</option>
<option value="4">Yearly</option>
</select>
</div>

我进入我的数据库FrequencyType = "1",但我想要FrequencyType = NumberInt(1)

最佳答案

有一个更简单的方法:

只需使用 value*1 作为您的 id,这会将字符串转换为 int 而不更改值...假设 id 是整数。

所以结果是>

<div ng-app ng-controller="MyCtrl">
<select ng-model="selectedItem" ng-options="selectedItem*1 as selectedItem for selectedItem in values"></select>
selectedItem: {{selectedItem}}
</div>

这适用于更多情况,因为indexOf在对象中不可用,只能在数组中使用。此解决方案适用于以整数作为键的对象(例如,如果某些键丢失,或者如果您使用数据库 ID)

关于angularjs - ng-select 只给出字符串,但我想要一个整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19809717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com