Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created February 27, 2012 13:05
Show Gist options
  • Save thelinuxlich/1923630 to your computer and use it in GitHub Desktop.
Save thelinuxlich/1923630 to your computer and use it in GitHub Desktop.
@VM =
estados: KO []
cidades: KO []
funcionario: new Funcionario() # KO model
VM.funcionario.estado = KO("SP").intercept (value) ->
if typeof value is "object"
@(value.value)
VM.carregaCidades(value.callback)
else if typeof value is "string"
@(value)
VM.carregaCidades()
# Carrega cidades, verificando primeiro no IdentityMap se não há um objeto guardado.
VM.carregaCidades = (callback) ->
Cidade.index {estado: VM.funcionario.estado(),__cache: true},(data) ->
VM.cidades Cidade.createCollection data, (item) ->
{id: item,nome: item}
if VM.funcionario.id() is ""
if VM.funcionario.estado() is "SP"
VM.funcionario.cidade "MOGI DAS CRUZES"
callback() if typeof callback is "function"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment