[英]Bind data based on the drop down selection from JSON input in AngularJS
[英]Bind JSON to Angularjs input
我得到了一些这样的JSON:
[{
"Id": 0,
"Text": "Item 1",
"Selected": 1
}, {
"Id": 1,
"Text": "Item 2",
"Selected": 1
}]
和这样的输入:
<input type="text"
value="{{question.postObjs}}"
我想要的是输入中唯一的属性“ Text”作为列表。
Item 1, Item 2, ...
这有可能吗? 我试了一会儿,什么也没用:-(
在您的控制器中:
scope.text = '';
for (var value in scope.question.postObjs){
scope.text = scope.text + value.Text;
}
在您的输入中:
<input type="text" value="{{text}}" />
要么
<input type="text" ng-model="text" />
像这样在AngularController中编写一个方法
$scope.getText(){
// which will return ["Item1", "Item2"]
}
并且在视图中,您可以使用方法填充值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.