weixin_33696106 2019-12-28 08:02 采纳率: 0%
浏览 50

jQuery不需要的selectedIndex

 function getrecipe(q) {
  var apiKey = "";
  $.ajax({
    url: "https://api.spoonacular.com/recipes/search",
    data: "apiKey=" + apiKey + "&query=" + q,
    async: 'true',
    success: GetReci
  });

  function GetReci(response) {
    // console.log(response)
    var reci = "";
    var i = 0;
    var GetRecipe_Arr = response.results;
    $.each(GetRecipe_Arr, function(index,value){
      var title = GetRecipe_Arr[i].title;

      i = i + 1;
    })

    $('#recipeoutput').html(reci);

    $('#recipeoutput li').on('tap', function (e) {
      recipeIndex = $(this).index();
      $(":mobile-pagecontainer").pagecontainer("change", "#searchrecipedetailpage", { role: "page" 
    });
    });

    $(document).on('pageshow', '#searchrecipedetailpage', function () {
      var id = GetRecipe_Arr[recipeIndex].id
      console.log(id)
      var title = GetRecipe_Arr[recipeIndex].title;
      $.ajax({
        url: "https://api.spoonacular.com/recipes/" + id + "/information",
        data:  "apiKey=" + apiKey + "&includeNutrition=true",
        async: 'true',
        success: function(response){
          console.log(response);
        }
      });
   })
}

The first time search the id was fine...but after the second time search, I get enter image description here extra id that is not I tapped on. Sorry for my bad explanations, how can i improve my codes and make it work well?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了