jquery raty函数不能与ajax一起使用

时间:2015-11-30 06:53:14

标签: jquery jquery-ui jquery-mobile jquery-plugins

我正在使用ajax加载一些食谱细节,并且我正在显示每个食谱的评级。但是我的代码不能正常工作。如果可以,请查看我的代码并帮助我。提前谢谢。

$("#btnsearch").click(function(){                
            if($("#ing").val()=="")
            {
                alert("Please enter a comma separated list to search");
                return false;
            }   
            var ing = $("#ing").val();
            $.ajax({
                method: "POST",
                url: urlsearch,
                data: {"ing":ing},
                dataType: "json"
            }).done(function(recipes){
                var total_recipes = recipes.length;
                var str2 = "";
                var resp_details = "";
                if(total_recipes)
                {
                    var myid = 1;
                    var str_ing = "";
                    var length_str_ing = 0;
                    for(var i=0;i<total_recipes;i++)
                    {
                       // var _id = i+1;
                        //console.log(recipes[i]);
                        str_ing = recipes[i].ingredients.join("<br />");                            

                        str2+='<li><a href="#item'+myid+'"><img src="http://icuizine.com/image/wh/recipe/100/100/'+recipes[i].recipe_image+'" align="absmiddle" />&nbsp;&nbsp;'+recipes[i].title+'<span class="ratings" score="'+recipes[i].rating+'"></span></a></li>';
                        resp_details += '<div class="panel" data-title="'+recipes[i].title+'" id="item'+myid+'"><div style="width:100%;clear:both;margin-top:20px;text-align:center;"><img src="http://icuizine.com/image/wh/recipe/100/100/'+recipes[i].recipe_image+'" /></div><div style="margin-top:20px;width:100%;text-align:center;"><b>Cuisine:&nbsp;</b>'+recipes[i].category+'<br /><b>Calories:</b>&nbsp;'+recipes[i].calories+'<br /><br /><b>'+recipes[i].total_ingredients+' Ingredient(s)</b><br /><br />'+str_ing+'</div><div style="width:100%;clear:both;text-align:center;margin-top:20px;text-align:left;">'+recipes[i].about+'</div></div>';
                        myid = myid+1;

                    }
                    //console.log(recipes[0].title);                                                
                }
                var str = '<ul class="list">';
                str += str2;
                str += '</ul>';
                $("#recipes_list").html(str);
                $("#recipe_details").html(resp_details);
               setTimeout(function(){
                    $(".ratings").each(function(){
                        var score = parseFloat($(this).attr("score"));                    
                        $(this).raty({score:score});
                    });
                },500);
            });
        });

0 个答案:

没有答案