【问题标题】:Dashcode Web App: How to programmatically manipulate bound array in dataSource?Dashcode Web App:如何以编程方式操作数据源中的绑定数组?
【发布时间】:2010-11-09 21:34:04
【问题描述】:

我已经开始使用 Dashcode 为我们的一些 Cocoa 工具编写一个显示报告数据的界面。我正在使用 Dashcode 数据源和绑定来填充 WebView 中的元素,到目前为止一切似乎都运行良好。

我的 dataSource 中的一个对象是我想以编程方式操作的对象数组。我可以很好地更改数组中的对象值,但是如果我想替换数组或数组中的任何对象,我的绑定表将无法观察添加的对象。

这是我认为可以让我轻松地用新内容替换绑定数组的代码:

var dataSource = dashcode.getDataSource("reportData");
var newDetailArray = testArray();
dataSource.setValueForKeyPath(newDetailArray, "content.detailArray");

但这会引发异常:

Exception while binding "content" to keypath "arrangedObjects " TypeError: Result of expression 'this.object.valueForKeyPath' [undefined] is not a function.

我缺少什么可以让我轻松地以编程方式操作数组的内容吗?

【问题讨论】:

    标签: javascript data-binding safari dashcode


    【解决方案1】:

    这里有一个解决问题的方法:

    1) 首先在 main.js 中定义一个 KVO 对象。这一步很重要,因为给定数据源的数据必须是可绑定的:

    anObj = Class.create(DC.KVO, {
        constructor: function(name) {
            this.name = name;
        }
    });
    

    2) 创建一个包含属于“anObj”类的对象的数组:

    function switchContent(event)
    {   
        var myPerson = new anObj('Paul');
        var myArray = new Array();
        myArray.addObject(myPerson);
    
        // 'dataSource' has to be defined in Dashcode as usual
        var ds = dashcode.getDataSource('dataSource');
    
        // replace content of datasource ds with myArray
        ds.setContent(myArray);   
    }
    

    希望这些信息对您有所帮助!

    【讨论】:

    • 感谢您的帮助!在时间的本质上,我们创建了一个解决方法,但它与您所展示的相去甚远。这是否记录在 developer.apple.com 上的某个地方?再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2021-10-19
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多