Jhipster:如何在一个实体中保存多个记录

时间:2017-07-05 18:12:21

标签: jhipster

我需要在循环中保存多个记录。在dialog.js中,我得到了正确的对象,我发送给服务js保存。仅在循环中调用服务js。当我运行这个服务时,在对话框js循环之后调用js save函数。这是怎么回事?如何在循环中保存数据?

对话框的controller.js

class RSpec::Core::ExampleGroup 
  def instance_exec(*args,&blk)
    if args.first.is_a?(RSpec::Core::Example)
      self.define_singleton_method(:current_metadata_description) do
        args.first.full_description
      end
    end
    super(*args,&blk)
  end
end

这是我的timesheet.service.js

function save () {
     vm.isSaving = true;

     for(var i in resourceData)
     {

         vm.timesheet.sunday=resourceData[i].sunday;
         vm.timesheet.monday=resourceData[i].monday;
         vm.timesheet.tuesday=resourceData[i].tuesday;
         vm.timesheet.wednesday=resourceData[i].wednesday;
         vm.timesheet.thursday=resourceData[i].thursday;
         vm.timesheet.friday=resourceData[i].friday;
         vm.timesheet.saturday=resourceData[i].saturday;
         vm.timesheet.resource=resourceData[i].saturday;
         vm.timesheet.resource=resourceData[i];

        Timesheet.save(vm.timesheet,onSaveSuccess, onSaveError);

 }

1 个答案:

答案 0 :(得分:0)

您可能必须编写递归函数,具体取决于返回的承诺。

Timesheet.save(vm.timesheet,onSaveSuccess, onSaveError);

这将返回一个调用onSaveSuccess方法的promise。

中的函数

function onSaveSuccess(){
// Need some recursive logic
}

或尝试实施此答案。

Need to call angular http service from inside loop and wait for the value of the service to return before executing code below call