find不是函数jquery
美好的一天,
我有我的观点,我在尝试渲染模板
和ajax电话
//ajax starts here... //.... success: function (data) { $.each(data, function (index, item) { var clone = $('#template').clone().html(); console.log(clone); parent.append(clone); clone.find('.editar').attr('href', editarUrl + '/' + item.Id); clone.find('.centrar').text(item.Titulo); clone.find('.index').attr('href', indexUrl + '?CursoId' + item.Id); clone.find('.image').attr('src', item.ImagenUrl); clone.find('.description').text(item.Descripcion); })
我使用控制台日志来查看变量克隆是否包含html,它确实存在。我的问题是我收到一条消息>>> find is not a function。
我该怎么办? 谢谢。
问题是因为clone
是一个包含#template
元素的HTML的字符串。 它不是一个jQuery对象。 这就是你得到错误的原因。
要解决此问题,您需要在jQuery对象中引用克隆的内容。 您可以通过使用appendTo()
并存储引用来实现。 像这样的东西:
success: function (data) { $.each(data, function (index, item) { var html = $('#template').html(); var $clone = $(html).appendTo(parent); $clone.find('.editar').attr('href', editarUrl + '/' + item.Id); $clone.find('.centrar').text(item.Titulo); $clone.find('.index').attr('href', indexUrl + '?CursoId' + item.Id); $clone.find('.image').attr('src', item.ImagenUrl); $clone.find('.description').text(item.Descripcion); }); });
- jQuery Dialog-Postback但UpdatePanel没有更新
- 在ajax调用中不存在所需的防伪表单字段“__RequestVerificationToken”
- 使用jQueryAjax“GET”调用WebMethod
- Ajax Request使用POST使用MVC和$ .ajax调用返回HTTP错误500?
- setInterval在Ajax请求后停止
- 通过Jquery使用Ajax调用函数/数据库更新
- 在UpdatePanel中使用JQuery UI datepicker
- 在UpdatePanel中从jQuery submit()中防止ASP.net __doPostback()
- 如何使用ASP.NET MVC中的jQuery ajax方法将数据列表发送到Controller Action方法?