我想在這個Demo:
http://www.crazyjs.org/demo/calendar/
在這個showFu':function回調函數裡,根據傳進來的日期,進行比對,獲取該日期的價格,比如傳進來的是2014-12-9日,那麼就到json數據裡來找這個價格信息,
我嘗試寫了一些getprice的方法,執行效率都太低了,,有哪位大俠幫幫忙,幫我根據這個Json寫個getprice的方法,展現到日歷上
附json數據
[ { "adate":"2014/12/3","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"1","lineid":"843","beforeDay":"5","week":"星期三"}, { "adate":"2014/12/4","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"2","lineid":"843","beforeDay":"5","week":"星期四"}, { "adate":"2014/12/5","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"3","lineid":"843","beforeDay":"5","week":"星期五"}, { "adate":"2014/12/6","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"4","lineid":"843","beforeDay":"5","week":"星期六"}, { "adate":"2014/12/7","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"7","lineid":"843","beforeDay":"5","week":"星期日"}, { "adate":"2014/12/7","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"5","lineid":"843","beforeDay":"5","week":"星期日"}, { "adate":"2014/12/11","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"8","lineid":"843","beforeDay":"5","week":"星期四"}, { "adate":"2014/12/19","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"6","lineid":"843","beforeDay":"5","week":"星期五"}]
<script>
data = [
{ "adate":"2014/12/3","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"1","lineid":"843","beforeDay":"5","week":"星期三"},
{ "adate":"2014/12/4","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"2","lineid":"843","beforeDay":"5","week":"星期四"},
{ "adate":"2014/12/5","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"3","lineid":"843","beforeDay":"5","week":"星期五"},
{ "adate":"2014/12/6","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"4","lineid":"843","beforeDay":"5","week":"星期六"},
{ "adate":"2014/12/7","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"7","lineid":"843","beforeDay":"5","week":"星期日"},
{ "adate":"2014/12/7","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"5","lineid":"843","beforeDay":"5","week":"星期日"},
{ "adate":"2014/12/11","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"8","lineid":"843","beforeDay":"5","week":"星期四"},
{ "adate":"2014/12/19","ss":"0","price":"1850","eprice":"1750","childpirce":"1950","id":"6","lineid":"843","beforeDay":"5","week":"星期五"}
];
function getprice(t) {
t = t.replace(/-/g, '/');
for(var i=0; i<data.length; i++) {
if(data[i].adate == t) return data[i];
}
}
alert(getprice('2014-12-19').price);
</script>