javascript - Is it correct update client side object with angular.copy response -


i have import functionality client side page display 'save button' or 'saved lable' depends on entity`s id.

enter image description here

here save function: response of created on server side, stored database , selected after object (after save i'd display stored value, 1 should have id (auto_increment pk)):

enter image description here

so, after saved order , got response stored value, need update passed argument order (to set order's id, that's saving button gone invisible , saved label showed).

i did angular.copy(entity, order), correct , there other practices applying , updating view's object response.

code here:

<tbody>     <tr ng-repeat="order in model.importedorders">         <td ng-bind="$index + 1"></td>         <td ng-bind="order.externalorderid"></td>         <td ng-bind="order.customerfullname"></td>         <td ng-bind="order.customeraddress"></td>         <td ng-bind="order.customerphone"></td>         <td ng-bind="order.orderitems[0].item.id"></td>         <td ng-bind="order.orderitems[0].purchaseprice.format('$n')" nowrap></td>         <td ng-bind="order.orderitems[0].sellingprice.format('$n')" nowrap></td>         <td ng-bind="order.vendor.id"></td>         <td ng-bind="order.manager.id"></td>         <td ng-bind="order.driver.id"></td>         <td ng-bind="order.deliveryprice.format('$n')" nowrap></td>         <td ng-bind="order.note"></td>         <td>             <a ng-if="!order.id"                ng-click="actions.save(order)"                href="#"                class="btn btn-xs btn-primary">Сохранить</a>              <span ng-if="order.id"                 class="label label-success">Сохранено</span>         </td>     </tr> </tbody> 

js function;

save: function(order) {     order$.save({ entity: order }).then(         function(msg) {             var entity = coalesce(msg, 'data.order');             angular.copy(entity, order);         }, function(msg) {             toaster$.pop('error', 'Ошибка на этапе сохранения заказа', coalesce(msg, 'data.description'));         }); } 

a little helper function:

function coalesce(obj, path) {     return $parse(path)(obj); } 


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -