[英]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>
詳細信息未獲取到文本框中,請指導原因
問題出在orderDetails[user.user_id]
,您的$scope.orderDetails
是一個數組,您需要索引來更新該數組中的值。
以及為什么要使用ng-change
, ng-model
本身會自動更新$scope.orderDetails
如果設置正確)。
在$scope
添加以下方法
$scope.getUserOrder = function(user) {
return $scope.orderDetails.filter(function(order) {
return order.user_id === user.user_id;
})[0]
}
並修改您的標記以使用此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>
可能會有一些錯字錯誤,請不要介意。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.