0
我有一個關於DashCode和dataSources的問題:我已經在javascript文件中定義了一個JSON對象,將它鏈接到一個dataSource並將公司名稱連接到用戶界面(一個'list'元素)。 JSON對象如下所示:如何將新項目添加(刪除)到Dashcode中的現有數據源?
{
items: [
{ company:'A', product:'a1', color:'red' },
{ company:'B', product:'b2', color:'blue' },
{ company:'C', product:'c3', color:'white' }
]
}
如何以編程方式向現有數據源添加(或刪除)其他「項目」?我已經使用了以下方法:
function addElement() {
var newElement = [{company:'D', product:'d4', color:'yellow' }];
var ds = dashcode.getDataSource('list');
ds.arrangedObjects.addObject(newElement);
}
和
function delElement()
{
var ds = dashcode.getDataSource('list');
if (ds.hasSelection()) {
var index = ds.selectionIndex();
ds.arrangedObjects.removeObjectAtIndex(index);
}
}
這段代碼的確增加了(刪除)的附加項添加到數據源。但是,當我使用list.filterpredicate搜索新項目的列表時,新項目將被忽略。
什麼是「正確」的方法來添加(或刪除)項目到現有的數據源編程?
您的幫助正在被讚賞!