Backbone.js 带主干的级联选择框
我有两个选择框县和市。当我改变国家时,我想更新与国家相对应的城市 模板:Backbone.js 带主干的级联选择框,backbone.js,Backbone.js,我有两个选择框县和市。当我改变国家时,我想更新与国家相对应的城市 模板: <select id="countries"> <% _(countries).each(function(country) { %> <option value="<%= country.id %>">`enter code here`<%= country.name %></option> <% }); %> </
<select id="countries">
<% _(countries).each(function(country) { %>
<option value="<%= country.id %>">`enter code here`<%= country.name %></option>
<% }); %>
</select>
<input id="countryId" name="countryId" type="hidden" value="<%= countryId %>" />
<select id="cities">
<% _(cities[countryId]).each(function(city) { %>
<option value="<%= city.id %>"><%= city.name %></option>
<% }); %>
</select>
如果我在setCountry中调用render,它会更新城市,但会刷新其他表单元素,如验证消息
如何更新代码,当我更改国家/地区时,它只刷新城市选择框?好的,当国家/地区更改时,您可以使用DOM操纵编辑选择中的选项,或者您可以将选择转换为主视图的子视图,只重新渲染该特定子视图而不是整个视图。您希望如何处理它?将模板分成两部分,只渲染需要的部分。
events: {
'change #countries': 'setCountry',
},
setCountry: function(element) {
this.model.set('countryId', element.target.value);
this.$el.find( "#countryId" ).val( this.model.get( "countryId" ) );
//this.render();
},