I have a Backbone.js collection that I would like to be able to sort using jQuery UI's Sortable. Nothing fancy, I just have a list that I would like to be able to sort. The problem is that I'm not sure how to get the current order of items after being sorted and communicate that to the collection. Sortable can serialize itself, but that won't give me the model data I need to give
我有一个Backbone.js集合,我希望能够使用jQuery UI的Sortable进行排序。 没有什么奇特的,我只是有一份我希望能够分类的清单。 问题是,我不知道如何获得项目的当前顺序后进行排序并将其传达给收集。 Sortable可以序列化自己,但是这不会给我需要给集合的模型数据。 理想情况下,我希望能够获得集合中模型的当前顺序的数组,并使用集合的重置方法,但我不确定如何获取当前顺序。 请分享任何想法或示例以获取当前模型订单
I am creating a small application with a JavaScript client (run in the browser) and a Node.js server, communicating using WebSocket. I would like to share code between the client and the server. I have only just started with Node.js and my knowledge of modern JavaScript is a little rusty, to say the least. So I am still getting my head around the CommonJS require() function. If I am creating
我正在用一个JavaScript客户端(在浏览器中运行)和一个Node.js服务器创建一个小应用程序,使用WebSocket进行通信。 我想分享客户端和服务器之间的代码。 我刚刚开始使用Node.js,至少可以说,我对现代JavaScript的了解有点生疏。 所以我仍然对CommonJS require()函数有所了解。 如果我使用'export'对象创建我的包,那么我看不到我如何在浏览器中使用相同的JavaScript文件。 我想要创建一组方法和两端使用的类
Im using backbone 1.1.0. Its been a while since I used Backbone but I'm sure I used to be able to easily overwrite the success handler for the save method. However, now i cannot seem to do it! My code is: model.save({}, { successs: function() { console.log('in my custom success handler'); } }); My custom handler doesnt not execute and the default success handler d
我使用主干1.1.0。 自从我使用Backbone以来,它已经有一段时间了,但我确定我曾经能够轻松地覆盖保存方法的成功处理程序。 但是,现在我似乎无法做到! 我的代码是: model.save({}, { successs: function() { console.log('in my custom success handler'); } }); 我的自定义处理程序不会执行,并且默认的成功处理程序会触发sync事件。 我在这里查看了这个问题并尝试了各种解决方案,但都没有成
I am trying to override Backbone.sync method for my model. The server returns status : 200 OK and model fires success callback in all cases. The server response is as follows status: 200 OK response : { statusCode: '0'; // 0 success, 1,2,3 errors ... } I have overided the sync function to throw error callback the cases work fine and throw error callback Although i am not able
我正在尝试为我的模型重写Backbone.sync方法。 服务器返回状态:200 OK,模型在任何情况下都会触发成功回调。 服务器响应如下 状态:200 OK 回应:{statusCode:'0'; // 0成功,1,2,3错误...} 我已经覆盖同步函数抛出错误回调的情况下工作正常,并抛出错误回调 虽然我无法将任何自定义选项传递给错误回调。 sync : function(method, model, options) { var self = this, config = {}; var newError = func
I've read that the return value from a Backbone model fetch statement is a jqXHR object, and that you should be able to abort it like so: var xhr = myBackboneModel.fetch(); // .... xhr.abort(); However, I get a 'Uncaught TypeError: undefined is not a function' error when trying to call abort. Inspecting xhr shows it contains a number of other methods (promise, resolve, fail, and a
我读过来自Backbone模型获取语句的返回值是一个jqXHR对象,并且您应该能够像这样终止它: var xhr = myBackboneModel.fetch(); // .... xhr.abort(); 但是,尝试调用中止时,出现'Uncaught TypeError:undefined不是函数'错误。 检查xhr显示它包含许多其他方法(承诺,解决,失败和更多)但不中止。 我使用的是Backbone 1.1.0。 任何想法可能会导致这... ...?
EDIT 1 : This question is not valid anymore. For more info check EDIT #2 at the end of this question. The backbone docs say that Backbone.Model.save function returns a jqXHR objects if validation is successful, otherwise it returns false. So if a validation method is not defined, the model.save method should return a jqXHR but it actually returns 'undefined'. model.fetch works fine a
编辑1 :这个问题不再有效。 欲了解更多信息,请查看本问题最后的编辑#2。 骨干文档说,如果验证成功,Backbone.Model.save函数返回一个jqXHR对象,否则返回false。 所以如果没有定义验证方法,model.save方法应该返回一个jqXHR,但实际上它返回'undefined'。 model.fetch正常工作并返回一个jqXHR对象。 jqXHR对象对于链接其他被缓存的对象很有用。 我正在调用多个模型的保存,并希望在所有保存方法完成时更新U
I'm trying to use backbone.js in a project and having trouble when trying to update a model with the fetch method. my model is as follows (singleton object as I only ever want one instance) define([ 'underscore', 'backbone' ], function (_, Backbone) { var UserModel = Backbone.Model.extend({ defaults: { name: "", loggedIn: false, user: "null", pass: "nul
我试图在项目中使用backbone.js,并尝试使用fetch方法更新模型时遇到问题。 我的模型如下(单例对象,因为我只想要一个实例) define([ 'underscore', 'backbone' ], function (_, Backbone) { var UserModel = Backbone.Model.extend({ defaults: { name: "", loggedIn: false, user: "null", pass: "null" }, prepare: function (options) { this.loggedIn = false;
i want to override the fetch method in models as well as in collections for fetching the data from localstorage when there is no network connection. This is a fetch function inside a collection fetch:function(){ if(online){ return Backbone.Collection.prototype.fetch.call(this) ; }else{ // return Backbone.Collection.fetch event - with data from localstorage } } i am facing
我想覆盖模型以及集合中的获取方法,以便在没有网络连接时从localstorage获取数据。 这是一个集合中的获取函数 fetch:function(){ if(online){ return Backbone.Collection.prototype.fetch.call(this) ; }else{ // return Backbone.Collection.fetch event - with data from localstorage } } 我在这里面临2个问题 a。成功或错误功能未被执行 this.collection.fetch({ success: function(data){ .
I have a drag&drop functionality in my web app. As the user releases the mouse after a drag&drop, the position of the object is saved to the server using Backbone's save() method on the model. When the server responds, it triggers a set() on the model with the returned properties. However, in the time the server was processing the request, the user might already have again dragged
我在我的网络应用程序中有一个拖放功能。 当用户在拖放之后释放鼠标时,使用模型上的Backbone的save()方法将对象的位置保存到服务器。 当服务器响应时,它会使用返回的属性在模型上触发set()。 但是,在服务器处理请求的时候,用户可能已经再次将对象拖动到不同的位置。 这会导致问题,因为服务器的响应现在会覆盖浏览器中对象的设置。 有没有办法阻止Backbone在执行save()之后从服务器获得响应之后执行set()?
我正在使用backbone.js,并试图从twitter获取一些json,但它不起作用,集合的长度为0.下面是代码。 var Tweet = Backbone.Model.extend(); var Tweets = Backbone.Collection.extend({ model: Tweet, url: 'http://api.twitter.com/1/favorites.json?screen_name=dhh', parse: function(response) { return response.results; } }); var tweets = new Tweets(); tweets.bind('reset', funct
我正在使用backbone.js,并试图从twitter获取一些json,但它不起作用,集合的长度为0.下面是代码。 var Tweet = Backbone.Model.extend(); var Tweets = Backbone.Collection.extend({ model: Tweet, url: 'http://api.twitter.com/1/favorites.json?screen_name=dhh', parse: function(response) { return response.results; } }); var tweets = new Tweets(); tweets.bind('reset', funct