閱讀363 返回首頁    go 技術社區[雲棲]


MAG中關於數組和COMBO,LIST的聯合使用例子(MAGList和MAGInputList)

直接貼代碼:

        MAGList list = new MAGList("MAGList例子");

		String[][] data = {
			{"水木社區", "https://www.newsmth.net", "1000", "水木", "2008-05-14"},
			{"京東商城", "https://www.360buy.com", "5000", "京東", "2009-04-14"},
			{"北京緩解擁堵網", "https://www.bjhjyd.gov.cn", "10", "北京市政府", "2010-12-14"},
			{"百度貼吧", "https://tieba.baidu.com", "8000", "白度", "2009-05-14"},
			{"新浪新聞", "https://news.sina.com.cn", "2000", "新浪", "2010-06-23"},
			{"新浪汽車", "https://audo.sina.com.cn", "1200", "新浪", "2011-06-21"},
			{"新浪房產", "https://house.sina.com.cn", "1800", "新浪", "2011-06-23"},
			{"新浪科技", "https://tech.sina.com.cn", "1400", "新浪", "2011-05-23"},
			{"新浪財經", "https://finance.sina.com.cn", "1300", "新浪", "2011-04-23"},
			{"新浪讀書", "https://book.sina.com.cn", "800", "新浪", "2010-04-23"},
			{"百度新聞", "https://news.baidu.com", "6000", "白度", "2011-07-08"},
			{"百度知道", "https://zhidao.baidu.com", "4500", "白度", "2011-01-11"},
			{"百度MP3", "https://mp3.baidu.com", "7700", "白度", "2011-03-28"},
			{"百度圖片", "https://image.baidu.com", "9800", "白度", "2011-02-09"},
			{"百度視頻", "https://video.baidu.com", "2300", "白度", "2011-02-11"},
			{"百度地圖", "https://map.baidu.com", "2200", "百度", "2011-03-31"},
		};

		for (String[] d:data) 
		{
			MAGCombo combo = new MAGCombo("");
			combo.setClass("combo_style");
			MAGLink link = new MAGLink(d[0], new MAGLinkURL(d[1]).setExpireHours(0), MAGLinkTarget.LINK_TARGET_BROWSER, "link");
			link.setClass("link_style");
			combo.addChild(link);

			MAGText text = new MAGText("訪問量:", d[2], "text");
			text.setClass("text_style");
			combo.addChild(text);

			MAGNote note = new MAGNote(d[3], d[4], "note");
			combo.addChild(note);
			list.addChild(combo);
		}
		
		MAGListOrderFieldSet order_fields = list.new MAGListOrderFieldSet();
		order_fields.addField("鏈接文字", "link._title", MAGListOrderFieldType.FIELD_TYPE_STRING);
		order_fields.addField("訪問量", "text._text", MAGListOrderFieldType.FIELD_TYPE_NUMBER);
		order_fields.addField("類別", "note._title", MAGListOrderFieldType.FIELD_TYPE_STRING);
		order_fields.addField("日期", "note._note", MAGListOrderFieldType.FIELD_TYPE_STRING);	

		//list.setOrderBy(order_fields);
		list.setItemsPerPage(3);
		
		int items_per_page = 3;
		double pages = (double)data.length/items_per_page;
		if(pages != (int)(pages)) 
		{
			pages = (int)(pages)+1;
		}
		list.setFooter("共" + (int)pages + "頁");
		list.setDescending(true);
		doc.addChild(list);
		
		
		MAGPanel panel = new MAGPanel("MAGInputList示例");
		
		MAGInputList input_list = new MAGInputList("網站列表", "_input_list", null);

		for (int i = 0; i<(data.length-1); i++) 
		{
			MAGCombo combo = new MAGCombo("item_"+i);
			combo.setClass("combo_style");
			MAGLink link = new MAGLink(data[i][0], new MAGLinkURL(data[i][1]).setExpireHours(0), MAGLinkTarget.LINK_TARGET_BROWSER, "link");
			link.setClass("link_style");
			combo.addChild(link);

			MAGText text = new MAGText("訪問量:", data[i][2], "text");
			text.setClass("text_style");
			combo.addChild(text);

			MAGNote note = new MAGNote(data[i][3], data[i][4], "note");
			combo.addChild(note);
			
			input_list.addChild(combo);
		}
		
		input_list.setOrderBy(order_fields);
		input_list.setDescending(true);
		
		input_list.setItemsPerPage(items_per_page);
		input_list.setFooter("共" + (int)pages + "頁");
		input_list.setDescending(true);
		panel.addChild(input_list);


最後更新:2017-04-02 16:47:50

  上一篇:go 友元類
  下一篇:go 如何從程序員轉型為項目經理