简体   繁体   English

如何使用ngResource发布对象?

[英]How can I post an object with ngResource?

var send_data = {
  speed:{min:$scope.speedSlider.minValue,max:$scope.speedSlider.minValue}],
  f_temp:{min:$scope.f_tempSlider.minValue,max:$scope.f_tempSlider.minValue},
  f_vol:{min:$scope.f_volSlider.minValue,max:$scope.f_volSlider.minValue},
  f_den:{min:$scope.f_denSlider.minValue,max:$scope.f_denSlider.minValue}
}

var settings = new Settings({truckId:$scope.truckId, data:send_data});

settings.$save();

I want to post this data to a Django backend and want the data to look like this: 我想将此数据发布到Django后端,并希望数据看起来像这样:

data {
 speed {
   max: 120,
   min: 10
 }
}

But the network call shows this under Form data 但是网络通话会在Form数据下显示此信息

truckId:poc-truck1 truckId:poc-truck1

data:[object Object] 数据:[对象对象]

To POST (create) a new resource object with AngularJS ngResource, use the save method. 要使用AngularJS ngResource POST(创建)新的资源对象,请使用save方法。

var send_data = {
  speed:{min:$scope.speedSlider.minValue,max:$scope.speedSlider.minValue}],
  f_temp:{min:$scope.f_tempSlider.minValue,max:$scope.f_tempSlider.minValue},
  f_vol:{min:$scope.f_volSlider.minValue,max:$scope.f_volSlider.minValue},
  f_den:{min:$scope.f_denSlider.minValue,max:$scope.f_denSlider.minValue}
}

//var settings = new Settings({truckId:$scope.truckId, data:send_data});

var settings = Settings.save(send_data);

The RESTful API usually assigns a new ID and returns the new resource object with the ID attached as a property. RESTful API通常会分配一个新ID,并返回带有ID作为属性附加的新资源对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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