2011-05-30 103 views
0

我想創建一個自定義複雜對象的控制器,但有嵌套列表綁定的問題。qooxdoo:嵌套列表數據綁定

我有一個JSON數據存儲它得到以下數據結構:

var data = [ 
     { 
      id: 1, 
      name: 'check all links if they work', 
      description: 'Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.', 
      tags: ['a', 'b', 'c'] 
     }, 
     { 
      id: 2, 
      name: 'check all titles', 
      description: 'Maecenas sed diam eget risus varius blandit sit amet non magna.', 
      tags: ['a', 'b', 'c'] 
     }, 
     { 
      id:3, 
      name: 'check layout in all browsers', 
      description: 'Maecenas sed diam eget risus varius blandit sit amet non magna.', 
      tags: ['a', 'b', 'c'] 
     }, 
     { 
      id:4, 
      name: 'validation if videos works fine', 
      description: 'Maecenas sed diam eget risus varius blandit sit amet non magna.', 
      tags: ['a', 'b', 'c'] 
     } 
     ]; 

我想這樣做的:就是這個列表綁定到自定義列表項的UI列表並綁定嵌套的「標籤」列表,一個屬性到一個自定義的UI控件,顯示一個標籤列表。

controllerCase.setDelegate({ 
     configureItem : function(item) { 
     }, 
     createItem : function() { 
      return new my.custom.Item(); 
     }, 
     bindItem : function(controller, item, id) { 
      controller.bindProperty("", "model", null, item, id); 
      controller.bindProperty("name", "name", null, item, id); 
      controller.bindProperty("description", "description", null, item, id); 
     controller.bindProperty("tags", "tags", null, item, id); 
     }); 

我想將my.custom.Item的'tags'屬性綁定到模型中的'tags'屬性,但總是得到一個空數組。

+1

嗯,這很奇怪,因爲bindProperty只複製引用,所以它不應該在乎它是否是一個數組。你是如何驗證它是一個空陣列? 一定要使用數據數組提供的方法,不要信任控制檯,因爲它可能會顯示一個空數組(使用.getItem(x)來檢查)。 – 2011-05-31 06:30:26

+0

馬丁,你絕對正確。我在控制檯中看到[],但是當我嘗試通過getItem(x)訪問元素時,我看到它們。所以,我用getItem調用代替迭代,並且一切正常。謝謝。 – 2011-05-31 15:34:12

回答

0

正如Martin所建議的那樣,應該使用數據數組類的方法。查看問題下的評論。