0

DS.FixutreAdapter当我无权访问后端时,我正在使用带有存根数据。我已经开始将 Ember Data 0.13 升级到 Ember Data 1.0 beta 2,但我不断收到错误消息:

"You made a request for a [user] with id [userid], but the adapter's response did not have any data"

不久前,当我移动夹具定义时,它(似乎是随机的)开始工作......

App.User.FIXTURES = [{
  id: 'muosuser',
  firstName: 'John',
  lastName: 'Smith'
}]

...从我文件的底部到顶部stub-data.js,但这可能只是侥幸。

有什么想法吗?Data 1.0 beta 2 的文档/指南尚未更新,FixtureAdapter在编写过渡指南等时似乎每个人都忽略了,所以我有点迷失在黑暗中。据我所知,旧的固定装置可能不再适用!

编辑:根据请求,这是我试图加载用户的地方:

App.MainRoute = App.AuthenticatedRoute.extend({

  redirect: function() {
    this.transitionTo('planner')
  }

, model: function() {
    return Ember.Object.create({
      user: this.store.find('user', this.controllerFor('login').get('username'))
    })
  }

, actions: {
    logout: function() {
      this.controllerFor('login').set('token', null)
      this.transitionTo('login')
    }
  }

})

同样根据请求,以下是全部内容stub-data.js

//
// Setup
//

App.Store.reopen({
  adapter: 'fixture'
})

//
// Users
//

App.User.FIXTURES = [{
  id: 'muosuser'
, firstName: 'John'
, lastName: 'Smith'
}]

//
// Snapshots
//

App.Snapshot.FIXTURES = [{
  id: Ember.generateGuid()
, regions: []
, networks: []
}]

//
// Networks
//

var networks = []
var ridicNet = ["Network ", "Krowten "]
for(var i = 0; i < 12; i++) {
  var newId = Ember.generateGuid()
  networks.push({
    id: newId
  , name: ridicNet[i%2] + (i+1)
  , terminals: []
  })
  App.Snapshot.FIXTURES[0].regions.push(newId)
}
networks.push({
  id: Ember.generateGuid()
, name: "k"
, priority: "p4"
, voiceRecognitionRequired: true
, terminals: []
})
App.Snapshot.FIXTURES[0].regions.push(networks[networks.length - 1].id)
App.Network.FIXTURES = networks

//
// Regions
//

App.Region.FIXTURES = [{
  // id: Ember.generateGuid()
  name: "Alaska"
, minLat: 53
, maxLat: 71
, minLon: -167
, maxLon: -131
}, {
  // id: Ember.generateGuid()
  name: "Brazil"
, minLat: -33
, maxLat: 5
, minLon: -74
, maxLon: -35
}, {
  // id: Ember.generateGuid()
  name: "Caribbean"
, minLat: 14
, maxLat: 23
, minLon: -85
, maxLon: -58
}, {
  // id: Ember.generateGuid()
  name: "Central Africa"
, minLat: -5
, maxLat: 15
, minLon: 5
, maxLon: 40
}, {
  // id: Ember.generateGuid()
  name: "Chile"
, minLat: -58
, maxLat: -18
, minLon: -76
, maxLon: -64
}, {
  // id: Ember.generateGuid()
  name: "China"
, minLat: 20
, maxLat: 53
, minLon: 74
, maxLon: 134.5
}, {
  // id: Ember.generateGuid()
  name: "Columbia"
, minLat: -5
, maxLat: 13
, minLon: -80
, maxLon: -67
}, {
  // id: Ember.generateGuid()
  name: "East Africa"
, minLat: 15
, maxLat: 33
, minLon: 15
, maxLon: 38
}, {
  // id: Ember.generateGuid()
  name: "Hawaii"
, minLat: 18
, maxLat: 29
, minLon: -180
, maxLon: -154
}, {
  // id: Ember.generateGuid()
  name: "Australia"
, minLat: -40
, maxLat: -11
, minLon: 113
, maxLon: 154
}]
App.Region.FIXTURES.map(function(fixture) {
  fixture.id = Ember.generateGuid()
  App.Snapshot.FIXTURES[0].regions.push(fixture.id)
})

//
// Terminals
//

var terminals = []
  // , terminalResults = []
for(var i = 0; i < networks.length * 2; i++) {
  var network = networks[Math.floor(i / 2)]
    , region = App.Region.FIXTURES[Math.floor(Math.random() * App.Region.FIXTURES.length)]
    , terminalId = Ember.generateGuid()
    // , latLngId = Ember.generateGuid()

  terminals.push({
    id: terminalId
  , name: 'Terminal ' + (i+1)
  , network: networks[Math.floor(i / 2)].id
  , location: region.id
  // , latLng: latLngId
  })
  if (!network.terminals)
    network.terminals = []
  network.terminals.push(terminals[i].id)
  if (!region.terminals)
    region.terminals = []
  region.terminals.push(terminals[i].id)

  // var minLat = Math.min(region.minLat, region.maxLat)
  //   , maxLat = Math.max(region.minLat, region.maxLat)
  //   , minLon = Math.min(region.minLon, region.maxLon)
  //   , maxLon = Math.max(region.minLon, region.maxLon)
  //   , lat = Math.random() * (maxLat - minLat) + minLat
  //   , lng = Math.random() * (maxLon - minLon) + minLon
  // terminalResults.push({
  //   id: latLngId
  // , terminal: terminalId
  // , lat: lat
  // , lng: lng
  // })
}
App.Terminal.FIXTURES = terminals
// App.TerminalResults.FIXTURES = terminalResults

App.Stub = App.Stub || {}

// Computation
App.Stub.computeAll = function() {
  this._complete = false
  this.computeTerminals()
  this.computeSatellites()
  this._complete = true
}

App.Stub.computeTerminals = function() {
  // Retain IDs
  var terminalResultIds = App.TerminalResults.FIXTURES && App.TerminalResults.FIXTURES.mapProperty('id') || []

  // Clear previously existing data
  App.TerminalResults.FIXTURES = []
  App.Terminal.FIXTURES.map(function(terminal) {
    delete terminal.results
  })

  // Generate new data
  App.Terminal.FIXTURES.forEach(function(terminal, index) {
    if ( !terminal.location ) { return }
    var regions = App.Region.FIXTURES
      , region = regions.findProperty('id', terminal.location)
      , minLat = Math.min(region.minLat, region.maxLat)
      , maxLat = Math.max(region.minLat, region.maxLat)
      , minLon = Math.min(region.minLon, region.maxLon)
      , maxLon = Math.max(region.minLon, region.maxLon)
      , lat = Math.random() * (maxLat - minLat) + minLat
      , lng = Math.random() * (maxLon - minLon) + minLon
    //   , demand = Math.ceiling(Math.random() * 96)

    // switch(demand) {
    //   case 12:
    //   case 48:
    //   case 96:
    //   case 32:
    //   case 64:
    //   case 16:
    //     demand *= 100
    //     break
    //   default:
    //     demand = 0
    // }

    terminal.results = terminalResultIds[index] || Ember.generateGuid()
    App.TerminalResults.FIXTURES.push({
      id: terminal.results
    , terminal: terminal.id
    // , lat: lat
    // , lng: lng
    // , demand: demand
    , location: [lat, lng]
    })
  })
}

App.Stub.computeSatellites = function() {
  // Retain IDs
  var positionIds = App.SatellitePosition.FIXTURES && App.SatellitePosition.FIXTURES.mapProperty('id') || []
    , satelliteIds = App.Satellite.FIXTURES && App.Satellite.FIXTURES.mapProperty('id') || []
    , beamIds = App.SatelliteBeam.FIXTURES && App.SatelliteBeam.FIXTURES.mapProperty('id') || []
    , carrierIds = App.SatelliteCarrier.FIXTURES && App.SatelliteCarrier.FIXTURES.mapProperty('id') || []

  // Clear previously existing data
  App.SatellitePosition.FIXTURES = []
  App.Satellite.FIXTURES = []
  App.SatelliteBeam.FIXTURES = []
  App.SatelliteCarrier.FIXTURES = []

  var satellitePositionOptions = [[[0, -135], [0, -45], [0, 45], [0, 135]]]
  function generateContour(cLat, cLng, radius) {
    var ret = []
    for(var k = 0; k < 60; ++k) {
      var lat = cLat + radius * Math.sin(k * Math.PI / 30)
        , lng = cLng + radius * Math.cos(k * Math.PI / 30)
      ret.push([lat, lng])
    }
    return ret
  }

  // Generate new data
  // SatellitePositions
  for(var spk = 0; spk < 1; ++spk) {
    var positionId = positionIds[spk] || Ember.generateGuid()
    App.SatellitePosition.FIXTURES.push({
      id: positionId
    , satellites: []
    })
    // Satellites
    var totalSatellites = 4
    for(var sk = 0; sk < totalSatellites; ++sk) {
      var satelliteIndex = spk * totalSatellites + sk
        , satelliteId = satelliteIds[satelliteIndex] || Ember.generateGuid()
      App.SatellitePosition.FIXTURES[spk].satellites.push(satelliteId)
      App.Satellite.FIXTURES.push({
        id: satelliteId
      , location: [satellitePositionOptions[spk][sk][0], satellitePositionOptions[spk][sk][1]]
      , beams: []
      })
      // Beams
      var totalBeams = 6
        , distroRadius = Math.random() * 20 + 10  // minimum: 10, maximum: 30
      for(var sbk = 0; sbk < totalBeams; ++sbk) {
        var beamIndex = satelliteIndex * totalBeams + sbk
          , beamId = beamIds[beamIndex] || Ember.generateGuid()
          , contourRadius = Math.random() * (distroRadius / 2) + (distroRadius / 10)
          , contourCenter = {
              lat: App.Satellite.FIXTURES[satelliteIndex].location[0]
                  + distroRadius * Math.sin(sbk * 2 * Math.PI / totalBeams)
            , lng: App.Satellite.FIXTURES[satelliteIndex].location[1]
                  + distroRadius * Math.cos(sbk * 2 * Math.PI / totalBeams)
            }
        App.Satellite.FIXTURES[satelliteIndex].beams.push(beamId)
        App.SatelliteBeam.FIXTURES.push({
          id: beamId
        , contour: generateContour(contourCenter.lat, contourCenter.lng, contourRadius)
        , carriers: []
        })
        // Carriers
        var totalCarriers = 4
        for(var sck = 0; sck < totalCarriers; ++sck) {
          var carrierIndex = beamIndex * totalCarriers + sck
            , carrierId = carrierIds[carrierIndex] || Ember.generateGuid()
          App.SatelliteBeam.FIXTURES[beamIndex].carriers.push(carrierId)
          App.SatelliteCarrier.FIXTURES.push({
            id: carrierId
          , txPower: Math.random()
          , loadFactor: Math.random()
          , ovsf: Math.floor(Math.random() * 256)
          })
        }
      }
    }
  }
}

//Reloading
function wait(ms) {
  var deferred = $.Deferred()
  setTimeout(deferred.resolve, ms)
  return deferred.promise()
}

App.Stub.reloadAll = function() {

  this.reloadTerminals()
  this.reloadSatellites()
}

App.Stub._recordReload = function(record) {
  record.reload()
}

App.Stub.reloadTerminals = function() {
  App.Terminal.find().forEach(this._recordReload)
  App.TerminalResults.find().forEach(this._recordReload)
}

App.Stub.reloadSatellites = function() {
  App.SatellitePosition.find().forEach(this._recordReload)
  App.Satellite.find().forEach(this._recordReload)
  App.SatelliteCarrier.find().forEach(this._recordReload)
  App.SatelliteBeam.find().forEach(this._recordReload)
}
4

2 回答 2

0

我的猜测是您的 stud-data.js 文件中存在某种错误,导致User夹具无法正确设置。固定装置肯定仍然有效。

于 2013-09-10T16:47:39.247 回答
0

找到了。我已经覆盖(并忘记了)find我的适配器以将其与第 3 方加载指示器挂钩。我打电话_super,但从来没有回过任何东西。我不知道为什么它以前有效,但我绝对可以看到为什么它现在不起作用。愚蠢的错误总是最难发现的!

于 2013-09-10T21:23:41.513 回答