0

有没有办法从现有的 Titanium.UI.DashboardView 添加或删除 DashboardItem?

4

1 回答 1

0

不幸的是,没有简单的方法来删除一个项目。您必须删除当前的仪表板视图并像这样重新创建它

var win = Ti.UI.createWindow({
    backgroundColor: '#13386c'
});

var button = Ti.UI.createButton({
    title: 'Change Items',
    top:10
});
win.add(button);

var dashboardData = [];
var itemData = [
  { name: 'account', badge: 1 },
  { name: 'cases', badge: 2 },
  { name: 'calls', badge: 3 },
  { name: 'contacts', badge: 4 },
  { name: 'emps', badge: 5 }, 
  { name: 'leads', badge: 6 },
  { name: 'meetings', badge: 7 },
  { name: 'opps',  badge: 8 }
];

for (var i = 0; i < itemData.length; i++)
{
    var item = Ti.UI.createDashboardItem({
        badge: itemData[i].badge,
        image:'/path/to/an/image.png',
        label: itemData[i].name
    });
    dashboardData.push(item);
}

var dashboard = Ti.UI.createDashboardView({
  data: dashboardData,
  top:100
});
win.add(dashboard);

button.addEventListener('click', function(e)
{
    dashboardData = [];
    win.remove(dashboard);
    dashboard = null;
    dashboard = Ti.UI.createDashboardView({
      top:100
    });
    win.add(dashboard);

    var newItemData = [
        { name: 'account', badge: 1 },
        { name: 'calls', badge: 3 },
        { name: 'emps', badge: 5 }, 
        { name: 'meetings', badge: 7 }
    ];

    for (var i = 0; i < newItemData.length; i++)
    {
        var item = Ti.UI.createDashboardItem({
            badge: newItemData[i].badge,
            image:'/path/to/an/image.png',
            label: newItemData[i].name
        });
        dashboardData.push(item);
    }
    dashboard.data = dashboardData;
});
win.open();

我把那个例子放在一起。我相信它也可以提高效率

于 2012-12-08T00:19:39.090 回答