如何在AngularJS的ng-options中设置value属性?

让人想犯罪 __ 提交于 2020-08-18 06:33:37

问题:

Here is what seems to be bothering a lot of people (including me). 这似乎困扰了很多人(包括我)。

When using the ng-options directive in AngularJS to fill in the options for a <select> tag, I cannot figure out how to set the value for an option. 在AngularJS中使用ng-options指令填写<select>标签的选项时,我无法弄清楚如何设置选项的值。 The documentation for this is really unclear - at least for a simpleton like me. 这方面的文档真的不清楚 - 至少对像我这样的傻瓜来说。

I can set the text for an option easily like so: 我可以像这样轻松设置选项的文本:

ng-options="select p.text for p in resultOptions"

When resultOptions is for example: 例如,当resultOptions

[
    {
        "value": 1,
        "text": "1st"
    },
    {
        "value": 2,
        "text": "2nd"
    }
]

It should be (and probably is) the most simple thing to set the option values, but so far I just don't get it. 它应该(并且可能是)设置选项值最简单的事情,但到目前为止我还没有得到它。


解决方案:

参考一: https://stackoom.com/question/ovwm/如何在AngularJS的ng-options中设置value属性
参考二: https://oldbug.net/q/ovwm/How-do-I-set-the-value-property-in-AngularJS-ng-options
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!