我有类.knob
的动态创建输入的集合,我需要应用knob.js插件$(".knob").knob();
但是当我调用函数时DOM是空的。
问题是 - 当我必须调用插件时,哪种方式更好?
我的模板
<script id="UserProjectTemplate" type="text/template">
...
<input class="knob" data-angleOffset=90 data-linecap=round value="35">
</script>
列出项目视图
var UserProjectsItemView = Backbone.View.extend({
...
template: _.template($("#UserProjectTemplate").html()),
render: function () {
$(this.$el).append();
$(this.$el).html(this.template(this.model.toJSON()));
return this;
}
});
集合
var UserProjectsCollection = Backbone.Collection.extend({
...
url: function () {
return 'service/api.php/users/' + this.user_id + '/projects';
},
});
查看收集
var UserProjectsListView = Backbone.View.extend({
...
initialize: function () {
this.collection = new UserProjectsCollection(null, {user_id: 5});
this.collection.fetch({reset: true});
this.collection.on("reset", this.render, this);
},
render: function () {
var that = this;
_.each(this.collection.models, function (item) {
that.renderProject(item);
});
},
renderProject: function (item) {
var itemProjectView = new UserProjectsItemView({
model: item
});
this.$el.append(itemProjectView.render().el);
}
});