を比較:Javascriptが、私はこのコードを持つ2つのJSONに参加して
var json = '[{"id":113,"price":55,"start":"Sun, 24 Apr 2016 00:00:00 +0000","user_id":8},{"title":"","start":"2016-04-25T23:00:00.000Z","price":"115.7"},{"title":"","start":"2016-05-06T23:00:00.000Z","price":"115.7"},{"id":114,"price":45,"start":"Sun, 08 May 2016 00:00:00 +0000","user_id":9},{"title":"","start":"2016-05-08T23:00:00.000Z","price":"115.7"},{"id":111,"price":55,"start":"Wed, 01 Jun 2016 00:00:00 +0000","user_id":11},{"title":"","start":"2016-06-01T23:00:00.000Z","price":"115.7"},{"id":110,"price":53,"start":"Fri, 03 Jun 2016 00:00:00 +0000","user_id":8}]';
moment.utc().valueOf();
function fulljson(data) {
data = jQuery.parseJSON(data);
start = moment.utc('Sun, 24 Apr 2016 00:00:00 +0000').valueOf()/86400000;
start = parseInt(start);
console.log('pocetak'+start);
now = moment.utc().valueOf()/86400000;
now = parseInt(now);
console.log('sada'+now);
end = moment.utc('Sun, 05 Jun 2016 00:00:00 +0000').valueOf()/86400000;
end = parseInt(end);
console.log('kraj'+end);
auction_end = parseInt('3');
now = now + auction_end;
console.log('a sada je '+now);
if (start > now) {
pocetak = start;
console.log(pocetak);
} else {
pocetak = now;
console.log(pocetak);
}
var array_of_all_dates = [];
for (i = pocetak; i < end; i++) {
var new_object = {
title: '1',
start: moment(i*86400000).utcOffset('+0000').format(),
price: '{{$article->lowest_bid}}'
};
array_of_all_dates.push(new_object);
}
document.write(JSON.stringify(array_of_all_dates));
console.log(array_of_all_dates);
};
fulljson(json);
ので、最後にあなたは私がjson
とarray_of_all_dates
を持っていることがわかります。今、私はjson
array_of_all_dates
に参加にしたいが、同じstart
要素がすでにarray_of_all_dates
にexcistならば、
http://jsbin.com/qekijumobe/edit?html,js,output
はどのようにこれを行うには... array_of_all_datesからそれを削除し、json
からこれを置きますか?助けてください。
:
編集
、あなたはmergedItemsと呼ばれる1つのリストにリストの両方を追加するとしましょう私はあなたが求めていることを知っています。 ** start **プロパティの配列に**結合しようとしています。一致したオブジェクトが見つかると、 'array_of_all_dates'配列のそのオブジェクトを' json'配列の対応するオブジェクトに置き換えます。 これは間違いありませんか? –
はい、また、array_of_all_datesからdayを使用することもできます。これはmoment.utc(json.start).valueOf()/ 86400000と同じです。 jsonから... – Andrew
の2つの値を比較することができますが、両方から開始することもできます – Andrew