2013-03-03 43 views
0

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

$(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 +等在

+0

你应该看看http://jsrosettastone.com/一个网站,可以帮助你翻译YUI3和jQuery。 – juandopazo 2013-03-03 20:05:35

回答

0

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

​​

在回调里面,你可以使用:

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

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

是的,当您在'jQuery.getJSON'中包含'callback =?'时,它被视为JSONP。请参阅http://api.jquery.com/jQuery.getJSON/#jsonp – juandopazo 2013-03-03 16:46:21