Given the following js model:
class MyApp.Post extends Batman.Model
@encode options
Given the server side json (generated with rabl):
object @post
attributes :id, :category
node(:categories) {
Category::OPTIONS.map{ |option| { id: option, name: I18n.t(option) } }
}
And finally the binded view (haml):
# This binds the selected value to the model object
%select{ "data-bind" => "post.category" }
# Iterate over categories
%option{ "data-foreach-category" =>"post.categories",
# id as the value
"data-bind-value" => "category.id",
# name as the title
"data-bind" => "category.name",
# Selects the default received from the server (if any, for example when editing the model)
"data-bind-selected" => "category.basis"
Posted by Bonyiii to Bonyiii's deck (2014-04-02 20:50)