Form Controller Structure like:
Example Step One :- ( Controller Class)
define(function() {
var _controller;
var _countryData;
function _updateUI() {
/*====
method to load the data into the Widgets UI
====*/
_controller.view.segCountryList.widgetDataMap = {
"id" : "id",
"lblCountryName" : "name"
};
_controller.view.segCountryList.setData(_countryData);
}
function _loadData() {
var CountryModel = require("countrymodel");
_countryData = CountryModel.getAll();
konyConsole("Data : "+JSON.stringify(_countryData));
_updateUI();
}
function _bind() {
alert("binding");
}
function onDestroy() {
kony.print("onDestroy()"); //Cleanup
}
function onNavigate(params) {
kony.print("onNavigate()");
_controller=this; //capture reference to controller
_bind();
_loadData();
//retrieve data from model, setup the ui
}
return {
onNavigate : onNavigate,
onDestroy: onDestroy
};
});
//require : controller is :(in require modules) ==> model Class
define(function () {
/* jshint esnext: true */
var staticData = [
{ id: 1, name: "India" },
{ id: 2, name: "France" },
{ id: 3, name: "Germany" },
{ id: 4, name: "UK" },
{ id: 5, name: "Italy" },
{ id: 6, name: "Chile" },
{ id: 7, name: "Brazil" },
{ id: 8, name: "USA" },
{ id: 9, name: "Canada" }
];
function getAll() {
return staticData;
}
function getById(id) {
return staticData.find(country => country.id===id);
}
return {
getAll : getAll,
getById : getById
};
});