gpt4 book ai didi

javascript - 主干/下划线 js "too much recursion"和 "Inspect target crashed"错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:47:34 30 4
gpt4 key购买 nike

我已经为待办事项列表编写了一个代码,它工作正常,但有时会出错Backbone/underscore js“太多递归”和“检查目标崩溃”错误就像这是控制台..

HTML 代码:-

  <script type="text/template" id="item-template">
<div class="view">
<input class="toggle" type="checkbox" <%= completed ? 'checked' : '' %>>
<label><%- title %></label>
<input class="edit" value="<%- title %>">
<button class="destroy">remove</button>
</div>
</script>

主干 JS 代码:-

(function ($) {
'use strict';

var app = {}; // create namespace for our app

//--------------
// Models
//--------------
app.Todo = Backbone.Model.extend({
defaults: {
title: '',
completed: false
},
toggle: function(){
this.save({ completed: !this.get('completed')});
}
});

//--------------
// Collections
//--------------
app.TodoList = Backbone.Collection.extend({
model: app.Todo,
localStorage: new Store("backbone-todo")
});

// instance of the Collection
app.todoList = new app.TodoList();

//--------------
// Views
//--------------

// renders individual todo items list (li)
app.TodoView = Backbone.View.extend({
tagName: 'li',
template: _.template($('#item-template').html()),
render: function(){
this.$el.html(this.template(this.model.toJSON()));
this.input = this.$('.edit');
return this; // enable chained calls
},
initialize: function(){
this.model.on('change', this.render, this);
this.model.on('destroy', this.remove, this); // remove: Convenience Backbone's function for removing the view from the DOM.
},
events: {
'dblclick label' : 'edit',
'keypress .edit' : 'OnEnter',
'blur .edit' : 'close',
'click .toggle': 'toggleCompleted',
'click .destroy': 'destroy'
},
edit: function(){
this.$el.addClass('editing');
this.input.focus();
},
OnEnter: function(e){
if(e.which == 13){
this.close();
}
},
close: function(){
var value = this.input.val().trim();
if(value) {
this.model.save({title: value});
}
this.$el.removeClass('editing');
},
updateOnEnter: function(e){
console.log(this);
console.log(e);
// if(e.which == 13){
// this.close();
// }
},
toggleCompleted: function(){
this.model.toggle();
},
destroy: function(){
this.model.destroy();
}
});

// renders the full list of todo items calling TodoView for each one.
app.AppView = Backbone.View.extend({
el: '#todoapp',
initialize: function () {
this.input = this.$('#new-todo');
app.todoList.on('add', this.addAll, this);
app.todoList.on('reset', this.addAll, this);
app.todoList.fetch(); // Loads list from local storage
},
events: {
'keypress #new-todo': 'createTodoOnEnter'
},
createTodoOnEnter: function(e){
if ( e.which !== 13 || !this.input.val().trim() ) { // ENTER_KEY = 13
return;
}
app.todoList.create(this.newAttributes());
this.input.val(''); // clean input box
},
addOne: function(todo){
var view = new app.TodoView({model: todo});
$('#todo-list').append(view.render().el);
},
addAll: function(){
this.$('#todo-list').html(''); // clean the todo list
app.todoList.each(this.addOne, this);
},
newAttributes: function(){
return {
title: this.input.val().trim(),
completed: false
}
}
});

//--------------
// Initializers
//--------------

app.appView = new app.AppView();

})(jQuery);

当我在按键编辑时实现和 OnEnter 时,它给了我这个错误..我检查了“太多递归”错误何时出现..但无法弄清楚..

如果我的问题不清楚,请不要介意......

谢谢!!

最佳答案

也许你应该试试这个。我已经给出了进入的条件,但我的电话一直在重复,所以我声明按键事件和函数如下

events:{
"keyup #globalOrgSearchInput":"onEnter"
}

onEnter:function(event){
var me=this;`enter code here`
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
me.globalOrgSearch();
}
},

关于javascript - 主干/下划线 js "too much recursion"和 "Inspect target crashed"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19517329/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com