2013-03-03 41 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