如何将外部剩余 api 数据作为记录数组传递给模型?

How to pass external rest api data to a model as an Array of records?

我正在尝试使用我创建的 .net core 2.2 web api 并在 json 数据 键和值 中显示 [= =68=] 应用程序制作应用程序。我的 js 非常非常弱(因为我已经尝试在 googles 文档中重新使用 main example 7 天了,但没有任何实际进展)。

我已经解决了很多问题才得出最终的错误(我希望如此)。

当我将一些 REST API 数据提交到数据存储时。它要求:

错误:

The function queryRecords must return an array of records, but the 
array contained an element that was not a record. Error: The 
function queryRecords must return an array of records, but the 
array contained an element that was not a record.

9 月 22 日星期日 15:42:46 GMT-700 2019

Executing query for datasource Weather: (Error) : The function 
queryRecords must return an array of records, but the array 
contained an element that was not a record.
at loadWeatherDataSource (CallWeatherService:6:27)
at Weather.LocationTextBox.onValueChange:1:1
at Weather.LocationTextBox.onAttach:1:14

9 月 22 日星期日 15:42:46 GMT-700 2019

Executing query for datasource Weather failed.

服务器端代码

function clearEmailForm(){


       var url= 'https://xxx.azurewebsites.net/api/xxxxxx/3';


          var response1 = UrlFetchApp.fetch(url);
          var api1= response1;







  return JSON.parse(api1);
      }  

 function cal() {
   var coordinates =  clearEmailForm(); 


     return {
      forecast: coordinates.Scene,
      citystate: coordinates.imageurl
    };
  }
function calculateWeatherModel_() {

  var response;
  try {
    response = cal(); 

  } catch (error) {
    throw new Error('Error Unable to locate provided city: \"' + response +  '\".');
  }

  if (response === null) {
    throw new Error('null Unable to locate provided city: \"' + response + '\".');
  }

  var forecastPeriods = response.forecast;
  var citystate = response.citystate;
  var arr = [];


     var record = app.models.Weather.newRecord();

     arr.push(record.forcast = forecastPeriods  ); 

      var record = app.models.Weather.newRecord();

    arr.push(record.citystate = citystate);



    return arr;
  }

客户端代码

function loadWeatherDataSource() {
  app.datasources.Weather.load({
    failure: function (error) {
      displayTimedSnackBar(error.toString());
    }
  });
}

客户端代码

return calculateWeatherModel_();

在此提前感谢您提供的所有详细帮助。我完全不知所措,将不得不推迟一个关键项目。

我现在将学习并开始掌握 JS,因为我看到一个明确的需求!我的书和在线课程已准备就绪。如果我能在这个问题上得到一些详细的帮助,它现在就会给我的项目带来新的生命,而不是很久以后。谢谢你们!

我相信你的问题出在这里:

var arr = [];

var record = app.models.Weather.newRecord();

arr.push(record.forcast = forecastPeriods  ); 

var record = app.models.Weather.newRecord();

arr.push(record.citystate = citystate);

return arr;

这是错误的做法。应该是这样的:

var arr = [];
var record = app.models.Weather.newRecord();
record.forcast = forecastPeriods;
record.citystate = citystate;
arr.push(record);
return arr;

显然,为了让它起作用,您的计算模型应该有一个 forcast 字段和一个 citystate 字段。

参考:https://developers.google.com/appmaker/models/calculated#query_script_example