1
我已經有一個簡單的div,我希望骨幹在我的服務器上渲染一個select
框和options
。骨幹渲染不渲染選擇標籤
該選項似乎渲染得很好,但選擇框沒有。我相信這是一個簡單的調整,但似乎無法找到它。
我創建了它的簡化小提琴:http://jsfiddle.net/thunderrabbit/BNZY3/
的HTML
<div id="where_fields"></div>
我使用用途fetch()
來獲取數據的腳本。上面的小提琴硬編碼數據,但問題是相同的。
(function($){
var Field = Backbone.Model.extend();
var UnitFields = Backbone.Collection.extend({
url: '/<?php echo CONFIG_ADMIN_DIR; ?>/api/fieldnames/units',
model: Field
});
var BuildingFields = Backbone.Collection.extend({
url: '/<?php echo CONFIG_ADMIN_DIR; ?>/api/fieldnames/buildings',
model: Field
});
var FieldView = Backbone.View.extend({
tagName: "option",
initialize: function(){
_.bindAll(this, 'render');
},
events: {
"click":"clicked"
},
clicked: function(e) {
var data_type = this.model.get("DATA_TYPE");
if(data_type == "varchar") {
console.log("it's a varchar");
}
if(data_type == "int") {
console.log("it's an int");
}
},
render: function(){
$(this.el).attr('value', this.model.get('COLUMN_NAME')).html(this.model.get('display_name'));
return this;
}
});
var FieldsView = Backbone.View.extend({
tagName: "select",
el: $('#where_fields'),
initialize: function(){
_.bindAll(this, 'render', 'renderItem');
this.collection.bind('reset', this.render);
},
renderItem: function(model) {
console.log('rendr item');
var fieldView = new FieldView({model:model});
fieldView.render();
$(this.el).append(fieldView.el);
},
render: function(){
console.log('rendr');
this.collection.each(this.renderItem);
return this;
}
});
var units_fields = new UnitFields();
var buildings_fields = new BuildingFields();
var unitsView = new FieldsView({collection: units_fields});
var buildingsView = new FieldsView({collection: buildings_fields});
units_fields.fetch();
buildings_fields.fetch();
})(jQuery);
爲什麼我的骨幹腳本沒有渲染select
標籤?
太好了! http://jsfiddle.net/thunderrabbit/BNZY3/3/有更新的代碼。 –
+1你的前兩句話;他們澄清了很多! –