是否可以(如果可以,如何)将 jQuery 的appendTo 与$.Views 一起使用?

发布于 2025-01-03 14:59:34 字数 185 浏览 1 评论 0原文

以下是我尝试过但失败的两种方法:

//fails
$( $.Views('//home/home.ejs', {data:data}) ).appendTo('#home');

//fails
$( '//home/home.ejs', {data:data} ).appendTo('#home');

Here are two ways I have tried and failed:

//fails
$( $.Views('//home/home.ejs', {data:data}) ).appendTo('#home');

//fails
$( '//home/home.ejs', {data:data} ).appendTo('#home');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

櫻之舞 2025-01-10 14:59:34

我不熟悉 $.Views 但是,试试这个:

$( $.Views('//home/home.ejs', {data:data}) ).appendTo($('#home'));

或者这个:

$( '//home/home.ejs', {data:data} ).appendTo($('#home'));

当你调用appendTo时,你必须传递一个jQuery选择器作为参数,而不仅仅是选择器字符串......

I'm not familiar with $.Views but, try this:

$( $.Views('//home/home.ejs', {data:data}) ).appendTo($('#home'));

or this:

$( '//home/home.ejs', {data:data} ).appendTo($('#home'));

when you are calling appendTo, you have to pass a jQuery Selector as the parameter, not only the selector string...

原来是傀儡 2025-01-10 14:59:34

我发现了错误。它应该是 $.View 而不是 $.Views。但第二种方法还是不行。

//works
$( $.View('//home/home.ejs', {data:data}) ).appendTo('#home');

//fails
$( '//home/home.ejs', {data:data} ).appendTo('#home');

I found the error. It should have been $.View and not $.Views. But the second way still won't work.

//works
$( $.View('//home/home.ejs', {data:data}) ).appendTo('#home');

//fails
$( '//home/home.ejs', {data:data} ).appendTo('#home');
不奢求什么 2025-01-10 14:59:34

JavascriptMVC 重写了 jQuery 的一些基本方法。其中之一是 .html,允许指定视图的路径而不是内部 html:

$("#home").html('//home/home.ejs', {data:data});

现在,如果您想追加,则使用相同的功能覆盖 .append 方法:

$("#home").append('//home/home.ejs', {data:data});

JSMVC 文档: http://javascriptmvc.com/docs.html#!jQuery.fn.append

JavascriptMVC overrides some of jQuery's base methods. One of them is .html, allowing to specify a path to a view instead of the inner html:

$("#home").html('//home/home.ejs', {data:data});

Now, if you want to append, the .append method is overridden with the same functionality:

$("#home").append('//home/home.ejs', {data:data});

JSMVC Documentation: http://javascriptmvc.com/docs.html#!jQuery.fn.append

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文