我正在使用此站点中的拖放操作来使用此示例:
我在同一页面中使用 Dnd 项目类型示例创建容器。像这样;
源容器
var catalog = new dojo.dnd.Source("catalogNode", {
accept: ["inStock,outOfStock"]
});
catalog.insertNodes(false, [
{ data: "Wrist watch", type: ["inStock"] },
{ data: "Life jacket", type: ["inStock"] },
{ data: "Toy bulldozer", type: ["inStock"] },
{ data: "Vintage microphone", type: ["outOfStock"] },
{ data: "TIE fighter", type: ["outOfStock"] },
{ data: "Apples", type: ["inStock"] },
{ data: "Bananas", type: ["inStock"] },
{ data: "Tomatoes", type: ["outOfStock"] },
{ data: "Bread", type: ["inStock"] }
]);
catalog.forInItems(function(item, id, map){
// set up CSS classes for inStock and outOfStock
dojo.addClass(id, item.type[0]);
});
目标容器
var wishlist = new dojo.dnd.Source("wishlistNode", {
accept: ["inStock","outOfStock"]
});
这是我在做什么;
dojo.connect(dojo.byId('JsonBtn'), 'onclick', function() {
var catalogNode = document.getElementById("catalogNode");
//Get all nodes in the assignRoleListContainer
var container2 = catalogNode.getAllNodes();
var results="";
var catalog_arr = [];
var len = container2.length;
for(var i=0;i<len;i++){
results = catalogNode.childNodes[i].childNodes[0].nodeValue;
catalog_arr.push(results);
}
//Json
var myJSON2 = "";
myJSON2 = JSON.stringify({catalog: catalog_arr});
});
我设法转换了 Json 中的所有数据;
{"catalog":["Life jacket","Toy bulldozer","Wrist watch","Apples","Bananas","Bread","Tomatoes","Vintage microphone","TIE fighter"]}
但现在我想将项目转换为 json,但关于它们的类型,例如
如果输入库存
{"inStock":["Life jacket","Toy bulldozer","Wrist watch","Apples","Bananas","Bread"]}
如果输入 outOfStock
{"outOfStock":["Tomatoes","Vintage microphone","TIE fighter"]}
有什么建议吗?