选择HTML值是不显示字符串的整数 [英] Select HTML Value is integer not displaying string

查看:42
本文介绍了选择HTML值是不显示字符串的整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在选择显示时遇到问题

I am running into an issue with a select being displayed

我有一个samplemodel值,它是数据库中的一个整数.截至目前,我想进行如下选择,但是我希望它显示字符串.该值将以双向绑定标记显示,但是当我在选择值中选择字符串yes,no或na时,它根本不会显示该字符串或任何东西.

I have a samplemodel value that is an interger in the database. As of right now, I want to do a select as below, but I want it to display the string. The value will be displayed in my two way binding markup but when I select a string of yes, no, or na in the select value, it doesn't display the string or anything at all.

如何获取显示字符串与int的值.

How do I get my value to display the string vs a int.

{{samplemodel}}
<select class="input-large input-large-altered" ng-model="samplemodel">
            <option value="1">Yes</option>
            <option value="2">No</option>
            <option value="3">NA</option>
        </select>

推荐答案

尝试在您的选择上使用ng-options.您可以选择将模型绑定到这种方式.

Try using ng-options on your select. You can choose what you would like your model bound to that way.

示例:

 $scope.myArray = [
 {Val: 1, Display: 'Yes'},
 {Val: 2, Display: 'No'},
 {Val: 3, Display: 'NA'}
];
$scope.samplemodel = "Yes";

//给出对象的显示字符串

//Gives the Display string of the object

{{samplemodel}}
    <select class="input-large input-large-altered" ng-options="item.Display as item.Display for item in myArray" ng-model="samplemodel">
    </select>

OR

//给出对象的值

 <select class="input-large input-large-altered" ng-options="item.Val as item.Display for item in myArray" ng-model="samplemodel">
    </select>

或//给出整个对象

 <select class="input-large input-large-altered" ng-options="item as item.Display for item in myArray" ng-model="samplemodel">
        </select>

这是 plunkr 为您提供完整示例.

Here is the plunkr to give you a full example.

也要解释ng-options,它的工作原理类似于ng-options ="[value]作为[array]中[object]的[display]"

Also to explain ng-options it works like so ng-options="[value] as [display] for [object] in [array]"

这篇关于选择HTML值是不显示字符串的整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆