Model view controller 向余烬视图添加JQuery UI选项
假设我想修改Ember.js示例中的视图以调整其大小 执行此操作的JQuery代码是:Model view controller 向余烬视图添加JQuery UI选项,model-view-controller,ember.js,sproutcore-2,Model View Controller,Ember.js,Sproutcore 2,假设我想修改Ember.js示例中的视图以调整其大小 执行此操作的JQuery代码是: $("#container").resizable() 其中#container表示一个div。我不确定这个片段在应用程序结构中属于哪个位置。它是否在app.js中?下面列出了内容,我不确定哪种方法最适合放入上述代码段 Todos = Ember.Application.create(); Todos.Todo = Ember.Object.extend({ title: null, isDone
$("#container").resizable()
其中#container表示一个div。我不确定这个片段在应用程序结构中属于哪个位置。它是否在app.js中?下面列出了内容,我不确定哪种方法最适合放入上述代码段
Todos = Ember.Application.create();
Todos.Todo = Ember.Object.extend({
title: null,
isDone: false
});
Todos.todosController = Ember.ArrayController.create({
content: [],
createTodo: function(title) {
var todo = Todos.Todo.create({ title: title });
this.pushObject(todo);
},
clearCompletedTodos: function() {
this.filterProperty('isDone', true).forEach(this.removeObject, this);
},
remaining: function() {
return this.filterProperty('isDone', false).get('length');
}.property('@each.isDone'),
isEmpty: function() {
return this.get('length') === 0;
}.property('length'),
allAreDone: function(key, value) {
if (arguments.length === 2) {
this.setEach('isDone', value);
return value;
} else {
return !this.get('isEmpty') && this.everyProperty('isDone', true);
}
}.property('@each.isDone')
});
Todos.CreateTodoView = Ember.TextField.extend({
insertNewline: function() {
var value = this.get('value');
if (value) {
Todos.todosController.createTodo(value);
this.set('value', '');
}
}
});
Todos.MainView = Ember.View.extend({
templateName: 'main_view'
});
通常,当您处理这样的DOM操作插件时,我喜欢将其添加到视图的
didInsertElement
方法中,其中this.$()
是表示视图元素的jQuery对象
Todos.MainView = Ember.View.extend({
templateName: 'main_view',
didInsertElement: function(){
this._super();
this.$().resizable();
}
});
顺便说一句,todos示例已被取代,甚至已经非常过时。这对我不起作用,当我将此更改应用于todos源时,部分视图不会呈现。