Angular select 选项值属性中的数据绑定对象
Angular data binding object in value attribute of option in select
我在 option
中使用 ng-repeat
填充了一个 select
项目。我使用 angular 的数据绑定将 selected 项目的值设置为我的模型。但
由于某种原因, json 字符串中的 " 现在变成了 \" 。因此,稍后我无法在我的代码中访问 json 字符串中的属性。
<select id="concepts" class="form-control" ng-model='usecase.concepts' multiple title='-Select one or more primary concepts-' data-width="auto" >
<option ng-repeat='concept in concepten' value='{{concept}}'>{{concept.name}}</option>
</select>
概念 JSON 字符串如下所示:
{"name":"Concept1","description":"beschrijving"}
但是当我 select select 中的一个项目时,它看起来像这样:
{\"name\":\"Concept1\",\"description\":\"beschrijving\"}
稍后我想用所选概念的名称属性填充一些下拉列表,但由于反斜杠,我无法再访问名称属性。
我该如何解决这个问题,这样 value
就不会在 JSON 字符串中添加反斜杠?
备注: 使用 ng-options
代替 ng-repeat
效果很好,但我正在尝试使用 nya-bootstrap-select 我可以无法使用 ng-options
标签
我不建议将整个 JSON-Strings 作为值放入 select。如果您的说明包含更多文字/html,您可能 运行 会遇到麻烦。
最好在更改处理程序中设置 selected 概念,例如:
ng-change="updateSelectedConcepts()"
http://plnkr.co/edit/4ETrFlM0HrftAobTyvtS?p=preview
在 plunkr 中你可以看到,usecase.concepts
包含 selected 概念对象。
我在 option
中使用 ng-repeat
填充了一个 select
项目。我使用 angular 的数据绑定将 selected 项目的值设置为我的模型。但
由于某种原因, json 字符串中的 " 现在变成了 \" 。因此,稍后我无法在我的代码中访问 json 字符串中的属性。
<select id="concepts" class="form-control" ng-model='usecase.concepts' multiple title='-Select one or more primary concepts-' data-width="auto" >
<option ng-repeat='concept in concepten' value='{{concept}}'>{{concept.name}}</option>
</select>
概念 JSON 字符串如下所示:
{"name":"Concept1","description":"beschrijving"}
但是当我 select select 中的一个项目时,它看起来像这样:
{\"name\":\"Concept1\",\"description\":\"beschrijving\"}
稍后我想用所选概念的名称属性填充一些下拉列表,但由于反斜杠,我无法再访问名称属性。
我该如何解决这个问题,这样 value
就不会在 JSON 字符串中添加反斜杠?
备注: 使用 ng-options
代替 ng-repeat
效果很好,但我正在尝试使用 nya-bootstrap-select 我可以无法使用 ng-options
标签
我不建议将整个 JSON-Strings 作为值放入 select。如果您的说明包含更多文字/html,您可能 运行 会遇到麻烦。 最好在更改处理程序中设置 selected 概念,例如:
ng-change="updateSelectedConcepts()"
http://plnkr.co/edit/4ETrFlM0HrftAobTyvtS?p=preview
在 plunkr 中你可以看到,usecase.concepts
包含 selected 概念对象。