Using Backbone models with AngularJS

后端 未结 7 1549
攒了一身酷
攒了一身酷 2021-01-30 02:11

Recently I was thinking about the differences and similarities between Backbone.js and AngularJS.

What I find really convenient in Backbone are the Backbone-Models and t

相关标签:
7条回答
  • 2021-01-30 02:45

    Try taking a look at restangular.

    I have not implemented it anywhere, but I saw a talk on it a few days ago. It seems to solve the same problem in an angular way.

    Video: http://www.youtube.com/watch?v=eGrpnt2VQ3s

    0 讨论(0)
  • 2021-01-30 02:54

    You should look at the angularJS boilerplate with parse here. Parse is backbone like, but not exactly backbone. Thats where im starting my idea of a angularJS backboneJS project

    0 讨论(0)
  • 2021-01-30 02:58

    I was wondering the same-

    This is the use-case:

    salesforce mobile sdk (hybrid) has a feature called smartstore/smartsync, that expects backbone models/collection ,which gets saved to local storage for offline access .

    And you guessed it right, we want to use angularjs for rest of the hybrid app.

    Valid question.

    -Sree

    0 讨论(0)
  • 2021-01-30 03:01

    a working binding for example above... http://jsbin.com/ivumuz/2/edit

    it demonstrates a way for working around Backbone Models with AngularJS. but setters/getters connection would be better.

    0 讨论(0)
  • 2021-01-30 03:04

    Valid question for sure.

    Lot of limitations with the current implementation of $resource, which among others doesn't have internal collection management like Backbone.Collection. Having written my own collection/resource management layer in angular (using $http, not $resource), I'm now seeing if I can substitute much of the boilerplate internals for backbone collections and models.

    So far the fetching and adding part is flawless and saves code, but the binding those backbone models (or the attributes within, rather) to ng-models on inputs for editing is not yet working.

    @ericclemmons (github) has done the same thing and got the two to marry well - I'll ask him, get my test working, and post the conclusion...

    0 讨论(0)
  • 2021-01-30 03:06

    Had a similar idea in mind and came up with this idea: Add just a getter and setter for ever model attribute.

    Backbone.ngModel = Backbone.Model.extend({
            initialize: function (opt) {
             _.each(opt, function (value, key) {
                 Object.defineProperty(this, key, {
                     get: function () {
                         return this.get(key)
                      },
                     set: function (value) {
                         this.set(key, value);
                     },
                     enumerable: true,
                     configurable: true
                 });
             }, this);
         }
     });
    

    See the fiddle: http://jsfiddle.net/HszLj/

    0 讨论(0)
提交回复
热议问题