程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> json 回調函數-關於Javascrit日歷上顯示價格取值的問題

json 回調函數-關於Javascrit日歷上顯示價格取值的問題

編輯:編程綜合問答
關於Javascrit日歷上顯示價格取值的問題

我想在這個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>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved