backbone

Backbone collections representing tree data

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to load json data in form of a tree into Backbone Collection. I can't do this. Can anyone explain what I'm doing wrong? My very simple model: CTreeDataItem = Backbone . Model . extend ( { }); CTreeDataItems = Backbone . Collection . extend ( { model : CTreeDataItem }); And my load attepmt: var treeJs = [ { id : "tvRoot" , title : 'Root' , cssClass : 'root' , items : [ { id : "ti1" , title : 'Item1' , cssClass : 'item' , items : [ { id : "ti11" , title : 'SubItem11' , cssClass : 'subitem' }, { id : "ti12" , title : 'SubItem12

Stop backbone from adding surrounding divs to a view?

匿名 (未验证) 提交于 2019-12-03 02:45:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Handlebars.js as a templating tool for my Backbone.js app. My render functions in my views usually look like the following: var source = $("#round").html(); var template = Handlebars.compile(source); var context = JSON.parse(JSON.stringify(this.model)); var html = template(context); $(this.el).html(html); return this; The above is appended to the main app view through the following code(this is the code that calls the above code): $('div#round-container', this.el).append(roundView.render().el); My Handlebars template handles all

What are your best practices for backbone.js projects?

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Although I'm following backbone.js for some months and worked through a plethora of tutorials, I'm still not confident enough in backbone (or my skills regarding it) to use it in a larger project. My experience is that the backbone.js tutorials vary greatly in quality, some are terribly outdated (especially the sample todo app from the backbone docs). So I'd like to know about your backbone.js best practices/recipes? How do you handle nested collections/views? JSON serialisation? More complex queries between models? 回答1: Here is a list of

Backbone Fetch Related Models

匿名 (未验证) 提交于 2019-12-03 02:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm working on a Backbone app, but everything I've read so far is either about displaying a list of items (a TODO list for example) or a single item. Right now I have users, each user has a list of skills (pretty much like any game). I can easily get all users or a single user, the same for the skills but what if I want to get all the skills for a given user? How would I do that? I thought about just adding a property to the users with a new instance of a collection, something like this: var Users = Backbone.Model.extend({ skills: new Skills

Requirejs why and when to use shim config

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i read the requirejs document from here api requirejs.config({ shim: { 'backbone': { //These script dependencies should be loaded before loading //backbone.js deps: ['underscore', 'jquery'], //Once loaded, use the global 'Backbone' as the //module value. exports: 'Backbone' }, 'underscore': { exports: '_' }, 'foo': { deps: ['bar'], exports: 'Foo', init: function (bar) { //Using a function allows you to call noConflict for //libraries that support it, and do other cleanup. //However, plugins for those libraries may still want //a global.

requirejs - why loading module in define() works, but in require() doesn't

匿名 (未验证) 提交于 2019-12-03 01:44:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Code blow doesn't work, and the error msg is: Uncaught Error: Module name "text!templates/bookTemplate.html_unnormalized2" has not been loaded yet for context: _. Use require([]) define(['backbone', 'underscore', 'jquery'], function (Backbone, _, $) { var bt = require('text!templates/bookTemplate.html'); var BookView = Backbone.View.extend({ initialize: function () { this.render(); }, render: function () { var template = _.template(bt, { name: 'secret book' }); this.$el.html(template); } }); return BookView; }); then I move the "text

Bubbling events in nested Backbone (Marionette) Models / Collections

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We have a large Marionette App, that uses Backbone.trackit to monitor unsaved changes in our Models. We now have some nested models, in fact we have a Model, with a Collection of Models, that contain a Collection of Models. trackit doesn't support the top level model being marked as 'dirty' when the child models change - due to backbone not bubbling these change events. I know we could manually monitor these change events, but Im looking for a generic solution. Has anyone had any experience of the following libs or any other solutions for

“Why” does Backbone NOT have a save (PUT/POST) method for its collections - is it unRESTful?

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I asked a question a while back i.e. "How save an entire backbone collection?" . However what intrigues me is that why is a save method not offered? Is it unRESTful to save (PUT/POST) entire collections or is it uncommon to do so in the REST-land? GET : /MySite/ Collections - allowed by collection . fetch () POST : /MySite/ Collections - for the model ( s ) in the collection to be Posted when calling model . save () PUT : /MySite/ Collections /{ id } - for the model ( s ) to be updated individually GET : /MySite/ Collections /{ id

Require.js Error: Load timeout for modules: backbone,jquerymobile

匿名 (未验证) 提交于 2019-12-03 01:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use r.js to optimize my code but I keep running to this error: Tracing dependencies for: init Error: Load timeout for modules: backbone,jquerymobile The command I am running is this: $ java -classpath /Users/dixond/build-tools/rhino1_7R4/js.jar:/Users/dixond/build-tools/closurecompiler/compiler.jar org.mozilla.javascript.tools.shell.Main /Users/dixond/build-tools/r.js/dist/r.js -o /Users/dixond/Sites/omm_mobile/js/build.js My build.js file looks like this: ( { //appDir: "some/path/", baseUrl : ".", mainConfigFile : 'init.js',