简体   繁体   中英

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.

And why are you using ng-change , ng-model will itself update your $scope.orderDetails if set properly.

Add following method in your $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

<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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM