2016-04-28 96 views
0

我有一個widget.js與表和他的headerView我有一個控制器視圖。代碼:鈦 - 觸發從控制器到視圖

var table = Ti.UI.createTableView({ 
     id: ('table' + i), 
     data: tableData, 
     separatorStyle: OS_ANDROID ? Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_NONE : Ti.UI.iPhone.TableViewSeparatorStyle.NONE, 
     headerView: Alloy.createController("Principal/Componentes/LocalizacionRow", {parent: $.board}).getView() 
    }); 

我想使用$ .trigger將事件從LocalizacionRow傳遞到widget.js,但它不起作用。

我的代碼:

LocalizacionRow.js

if(!e.cancel){ 
      $.localizacion.text = e.data[0].value; 


      $.trigger('recargar'); 

      Ti.API.info("## Periódico: " + Ti.App.Properties.getString('media') + " " + $.localizacion.text); 
     } 

widget.js

var header = table.getHeaderView(); 
header.on('recargar', function(e){ 
    Ti.API.debug("--- Recargar"); 
}); 

「--- Recargar」 永遠不會顯示。我做什麼壞事?

我已經看到了這個代碼在這裏:http://www.tidev.io/2014/09/10/the-case-against-ti-app-fireevent-2/

在這裏:https://wiki.appcelerator.org/display/guides2/Controller+events

回答

1

如果您想要收到事件,您必須添加觸發器到LocalizacionRow控制器,如下所示:

var LocalizacionRowController = Alloy.createController("Principal/Componentes/LocalizacionRow", {parent: $.board}); 

LocalizacionRowController.on('recargar', function(e){ 
    Ti.API.debug("--- Recargar"); 
}); 

var table = Ti.UI.createTableView({ 
    id: ('table' + i), 
    data: tableData, 
    separatorStyle: OS_ANDROID ? Ti.UI.TABLE_VIEW_SEPARATOR_STYLE_NONE : Ti.UI.iPhone.TableViewSeparatorStyle.NONE, 
    headerView: LocalizacionRowController.getView() 
}); 
+0

謝謝,這對我有用! – amurcia

-1

你在控制器不會在視圖火災事件,試試這個:

var controller = Alloy.createController("Principal/Componentes/LocalizacionRow", {parent: $.board});  
var table = Ti.UI.createTableView({ 
    id: ('table' + i), 
    data: tableData, 
    separatorStyle: OS_ANDROID ?, 
    headerController : controller,               
    headerView: controller.getView(); 
}); 

var header = table.headerController; 
header.on('recargar', function(e){ 
     Ti.API.debug("--- Recargar"); 
}); 
+0

你在哪裏發射事件???我不明白....你的代碼就像我的代碼 – amurcia

+0

屬性headerController不存在 – amurcia

+0

你可以隨意添加禮貌;),這是不同的代碼我的朋友,只是試試 – HamidMly

相關問題