【问题标题】:jQuery code to YUIjQuery 代码到 YUI
【发布时间】:2013-03-03 00:20:00
【问题描述】:

如何将这个 jQuery 代码翻译成 YUI3?

$(document).ready(function() {
         $.getJSON('file.php?path=<?php echo $_GET['path']; ?>&callback=?', function (data) {
            $("#filemanager-ajax").html('');
            $.each(data, function (i, item) {

                $("#filemanager-ajax").append('<a class="link" href="' + item.id + '"><div class="product" data="' + item.path + '"><img src="' + item.thumb + '" title="' + item.thumb + '" class="thumbnail"/><div class="title">' + item.name + '</div><div class="description"></div>&nbsp;&nbsp;&nbsp;<strong>Filesize:</strong> ' + item.size + '<div style="clear:both;height:8px;"></div>&nbsp;&nbsp;&nbsp;about ' + item.date + ' ago<div style="clear:both;height:8px;"></div></div><div class="clear"></div></div></a>');

             });
         });
     });

我知道在 YUI 中它看起来像这样

YUI().use('json-parse', 'json-stringify', function (Y) {
    // JSON is available and ready for use. Add implementation
    // code here.
});

但是如何将 JSON 数据构建到 DIV 元素中并通过 +item.id+、+item.thumb+ 等输出

【问题讨论】:

  • 您应该查看jsrosettastone.com 一个帮助您将 YUI3 与 jQuery 相互转换的网站。

标签: jquery yui


【解决方案1】:

我认为你需要使用 JSONP 模块:

http://yuilibrary.com/yui/docs/jsonp/

在回调内部,你可以使用:

var node = Y.one("#filemanager-ajax");
node.empty();

Y.each(data, function(item, i) {
  node.append(...);
});

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-07-11
  • 2013-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-13
相关资源
最近更新 更多