我是 pebble js app dev 的新手,想要获取URL的 json 。所以我遇到了RSVP模块,但是我收到以下代码的错误:
/**
* 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);
});
错误是:
[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:如果使用 RSVP 不是要走的路,我怎么能说提取“顶级艺术家”或类似信息?