在Dashcode中将数据动态加载到List Controller中? (通过JSON)

时间:2009-12-28 15:10:08

标签: javascript iphone json list dashcode

你怎么能这样做?

1 个答案:

答案 0 :(得分:1)

//此对象实现列表的dataSource方法。 var listDataSource = {

// Sample data for the content of the list. 
// Your application may also fetch this data remotely via XMLHttpRequest.
_rowData: ["Item 1", "Item 2", "Item 3"],

// The List calls this method to find out how many rows should be in the list.
numberOfRows: function() {
    return this._rowData.length;
},

// The List calls this method once for every row.
prepareRow: function(rowElement, rowIndex, templateElements) {
    // templateElements contains references to all elements that have an id in the template row.
    // Ex: set the value of an element with id="label".
    if (templateElements.label) {
        templateElements.label.innerText = this._rowData[rowIndex];
    }

    // Assign a click event handler for the row.
    rowElement.onclick = function(event) {
        // Do something interesting
        alert("Row "+rowIndex);
    };
}

};

然后,在检查员中,将数据类型设置为“动态”,标签元素将成为您刚刚制作的“listDataSource”...