简体   繁体   中英

using rsvp module of ember.js in pebble js

I am new to pebble js app dev and want to get the json of a URL . So I came across the RSVP module however I get error for the following code:

/**
 * Welcome to Pebble.js!
 *
 * This is where you write your app.
 */

var UI = require('ui');
var ajax = require('ajax');
var RSVP = require('rsvp');

var Vector2 = require('vector2');
var userName = 'lamiastella';
var URL = 'http://www.last.fm/user/' + userName;
var card = new UI.Card({
  title:'last.fm stat',
  subtitle:'Fetching...'
});
card.show();


var getJSON = function(url) {
  var promise = new RSVP.Promise(function(resolve, reject){
    var client = new XMLHttpRequest();
    client.open("GET", url);
    client.onreadystatechange = handler;
    client.responseType = "json";
    client.setRequestHeader("Accept", "application/json");
    client.send();

    function handler() {
      if (this.readyState === this.DONE) {
        if (this.status === 200) { resolve(this.response); }
        else { reject(this); }
      }
    };
  });

  return promise;
};


ajax({ url: URL }, function(data){
 // var headline = data.match(/(.*?)<\/h1>/)[1];
  var title= data.match(/<h1>(.*?)<\/h1>/);
  card.subtitle(title);
  //card.subtitle(headline);
});

The error is :

[PHONE] pebble-app.js:?: JavaScript Error:
Error: Cannot find module 'rsvp'
at Object.loader.require (loader.js:34:11)
at require (loader.js:41:48)
at Object.loader (app.js:9:12)
at Object.loader.require (loader.js:44:10)
at require (loader.js:41:48)

PS: If using RSVP is not the way to go how can I say extract the "top artist" or similar information?

I am using RSVP in my Pebble.js app. Here's how I'm requiring it:

var RSVP = require('./rsvp.js');

The only problem is that it doesn't work in the emulator, due to a missing global variable in that environment.

Unfortunately, you can't include arbitrary libraries in Pebble.js.

In your specific case RSVP is a bit of overkill, you can just nest another callback inside of the ajax request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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