[英]fetch detail into the model view angularjs
$scope.orderDetails = [
{
"id":"115584",
"user_id":"78937",
"your_sys_global":null,
"created_at":"2017-12-08 05:03:20"
},
{
"id":"115585",
"user_id":"78936",
"your_sys_global":"MicSamse",
"created_at":"2017-12-08 05:03:21"
},
{
"id":"115586",
"user_id":"78938",
"your_sys_global":null,
"created_at":"2017-12-08 05:03:52"
}
];
<div ng-repeat="user in profiles track by $index">
<input
type="text"
name="your_sys_global_{{user.user_id}}"
ng-model="orderDetails[user.user_id].your_sys_global"
ng-change="saveOrder(user, orderDetails[user.user_id])"
>
</div>
Details are not fetching into the textbox please guide why 详细信息未获取到文本框中,请指导原因
The problem is at orderDetails[user.user_id]
, your $scope.orderDetails
is an array an you need index to update a value in that array. 问题出在
orderDetails[user.user_id]
,您的$scope.orderDetails
是一个数组,您需要索引来更新该数组中的值。
And why are you using ng-change
, ng-model
will itself update your $scope.orderDetails
if set properly. 以及为什么要使用
ng-change
, ng-model
本身会自动更新$scope.orderDetails
如果设置正确)。
Add following method in your $scope
在
$scope
添加以下方法
$scope.getUserOrder = function(user) {
return $scope.orderDetails.filter(function(order) {
return order.user_id === user.user_id;
})[0]
}
and modify your markup to use this method
并修改您的标记以使用此
method
<div ng-repeat="user in profiles track by $index">
<input
type="text"
name="your_sys_global_{{user.user_id}}"
ng-model="getUserOrder(user).your_sys_global"
>
</div>
There may be some typo mistakes, please don't mind. 可能会有一些错字错误,请不要介意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.