现在我从firebase获取数据
database = firebase.database();
var ref = database.ref('urls');
ref.on('value', gotData, errData);
function errData(err){
console.log('Error!');
console.log(err);
}
function gotData(data){
result = data.val()
const urls = Object.keys(result)
.filter(key => result[key].last_res > 5)
.map(key => ({url: 's/price/' + result[key].url_site + '/'}))
console.log(urls)
}
结果网址是
[ { url: '/cream/' },
{ url: '/salmon/' },
{ url: '/salmon-s/' } ]
我需要在url中发送数据替换如下
var sitemap = sm.createSitemap({
hostname: 'xxx.com',
urls: [ { url: 'xxx' },
{ url: 'xxx' },
{ url: 'xxx' } ]
});
我该怎么做?
答案 0 :(得分:0)
喜欢这个吗?
const a = [ { url: '/cream/' },
{ url: '/salmon/' },
{ url: '/salmon-s/' } ]
const sm = Object.assign({ hostname: 'xxx.com'}, { urls: a})
console.log(JSON.stringify(sm, null, 2));

答案 1 :(得分:0)
您可以制作createSitemap()
功能,并从gotData()
function gotData(data){
result = data.val()
const urls = Object.keys(result)
.filter(key => result[key].last_res > 5)
.map(key => ({url: 's/price/' + result[key].url_site + '/'}))
createSitemap(urls)
}
function createSitemap(urls) {
var sitemap = sm.createSitemap({
hostname: 'xxx.com',
urls: urls
});
}