我想创建一个锦标赛(如果不存在)和一个与锦标赛关联的匹配(如果不存在)。
let [match, created] = await Match.findOrCreate( {
  where: {scoreHome: 97, Tournament: {name: "USA South Men's Basketball"}}, 
  include: [Tournament]
})
Run Code Online (Sandbox Code Playgroud)
如果锦标赛“美国南部男子篮球”已经在数据库中(假设 ID 为 1),则应使用 TournamentId: 1 创建比赛。如果数据库中已经有比赛{scoreHome: 97 and TournamentId: 1},则不应创建比赛.
  let Match = sequelize.define('Match', {
    scoreHome: DataTypes.INTEGER,
    //...
  })
  Match.associate = models => {
    Match.belongsTo(models.Tournament)
  }
Run Code Online (Sandbox Code Playgroud)
编辑 这是错误:
[错误:无效值 [对象对象]]
这工作正常
let match = await Match.create({
    scoreHome: 97, Tournament: {name: "USA South Men's Basketball"}
  },{include: [Tournament]}
})
Run Code Online (Sandbox Code Playgroud) Ember Data的REST适配器以这种格式接受来自服务器的JSON:
摘自文档:http://guides.emberjs.com/v1.10.0/models/the-rest-adapter/
{
  "post": {
    "id": 1,
    "title": "Node is not omakase",
    "comments": [1, 2, 3]
  },
  "comments": [{
    "id": 1,
    "body": "But is it _lightweight_ omakase?"
  },
  {
    "id": 2,
    "body": "I for one welcome our new omakase overlords"
  },
  {
    "id": 3,
    "body": "Put me on the fast track to a delicious dinner"
  }]
}
Run Code Online (Sandbox Code Playgroud)
是否有可能从strongloop返回这种JSON格式?
我正在做一个插件.我尝试使用偏.在我的addon/templates/components/form.hbs中我得到了{{partial "pane"}}.我_pane.hbs是在插件/模板文件夹,但烬不能找到它:
未捕获错误:断言失败:无法找到名称为"窗格"的部分.
我也尝试将_pane.hbs放在插件/模板/组件中,但没有运气.我应该把它放在哪里被灰烬捡起来?
  let playersCell = `
    <td class="foo" colspan="2">
      <a href="example.com">
        <span class="bold">John Beluga</span>
         - Sarah Jay.
       </a>
    </td>
    `
let players = cheerio.load(playersCell)
players.find('a').html()
Run Code Online (Sandbox Code Playgroud)
我尝试将 html 字符串加载到 Cheerio.js 中并找到一个a标签,但我得到了
[类型错误:players.find 不是函数]
Console.log显示为players
  async traverse(url) {
    const ts = new TournamentScraper()
    const ms = new MatchScraper()
    const results = []
    const tournaments = await ts.run(url)
    for(let href of tournaments.map(t => t.href)){
      let matches = await ms.run(href)
      let pages = ms.getPages()
      let seasons = ms.getSeasons()
      //console.log(pages)
      //console.log(seasons)
      results.push(matches)
      for(let href of pages) {
        //console.log(href)
        matches = await ms.run(href)
        //console.log(matches)
        results.push(matches)
      }
    }
    return results
  }
Run Code Online (Sandbox Code Playgroud)
TournamentScraper 返回一个对象数组,通常如下所示:
{name: 'Foo', href: 'www.example.org/tournaments/foo/'}
Run Code Online (Sandbox Code Playgroud)
该链接指向锦标赛上赛季的首页。此页面包含其他季节的链接和分页器(如果有)。
MatchScraper 的运行返回一些数据,并设置实例的 dom 属性。getPages()并getSeasons()使用此属性,每个属性都返回一个链接数组。
结果的问题仅包含第一批匹配项。我可以在控制台日志中看到第二页的匹配项,但返回时它们不在结果数组中traverse。
我发现这条 …
我试着测试这个课程
class Scraper {
  async run() {
    return await nightmare
      .goto(this.url)
      .wait('...')
      .evaluate(()=>{...})
      .end
  }
}
Run Code Online (Sandbox Code Playgroud)
我的测试看起来像这样:
test('Scraper test', t => {
  new Scraper().run().then(() => {
    t.is('test', 'test')
  })
})
Run Code Online (Sandbox Code Playgroud)
测试失败:
测试完成后不运行任何断言
编辑
github上的存储库:https://github.com/epyx25/test
测试文件:https://github.com/epyx25/test/blob/master/src/test/scraper/testScraper.test.js#L12
javascript ×3
ember.js ×2
node.js ×2
async-await ×1
ava ×1
cheerio ×1
ember-cli ×1
loopbackjs ×1
nightmare ×1
promise ×1
sequelize.js ×1
strongloop ×1
testing ×1