0
我在我的Backbone应用程序中设置了一个编辑表单,该表单中填充了模型数据。我目前在没有ModelBinder的情况下工作,但想切换到ModelBinder。我可以使用Backbone.ModelBinder将选择框选项文本绑定到模型吗?
我有一个选择框,其中值映射到模型中的一个id,选定的选项文本应映射到模型上的字符串字段。用户可以选择从填充placeId和placeName或使用文本框填充placeName的下拉列表中填充模型。
我的问题是我如何得到这个 - $("#placeName option:selected").text()
到placeName选择器?
这里是我的模型和绑定对象:
// The Place Model
App.Models.Place = Backbone.Model.extend({
defaults: {
placeName: "",
placeId: ""
}
});
// Backbone Model Binder bindings
bindings: {
placeName:[
{selector: '$("#placeName option:selected").text()'},
{selector: '#textInputPlaceName'}] ,
placeId:'[name=placeName]'
}
下面是HTML。在UI有用于选择下拉菜单或输入栏复选框
<select id="placeName" name="placeName" class="inline">
<option value="0" selected="selected"></option>
<option value="444">exit 1</option>
<option value="555">exit 2</option>
<option value="666">exit 3</option>
</select>
<input id="textInputPlaceName" name="textInputPlaceName class="inline" disabled>
下面是一个小提琴相同的代码:http://jsfiddle.net/kDBvQ/
阅读此https://github.com/saskjavascript/Backbone---Bootstrap---Form-Validation –