Giter VIP home page Giter VIP logo

Comments (4)

kmalakoff avatar kmalakoff commented on August 10, 2024

Glad to hear you've enjoying it.

Hmmmm. If there was a single model with both apples and a pear, and you configured the reverse relationships for each, and you could traverse the model relationships from apple to apples then to pear when passed in.

var ApplesModel = Backbone.RelationalModel.extend({
    relations: [{
            type: Backbone.HasMany,
            key: "apples",
            relatedModel: AppleModel
        }, 
        {
            type: Backbone.HasOne,
            key: "pear",
            relatedModel: PearModel
        }
    ]
});

// plus add the reverse relationships between Apple -> Apples, Pear -> Apples.

Would that work?

from knockback.

mlarsson avatar mlarsson commented on August 10, 2024

Thank you for your quick response. Yes that would work but it would create an unwanted relation between the models. Apple(s) and the Pear model I mean. They don't really relate to each other on the model level. What I'm search for is for the viewmodel (AppleViewModel) to have access to the PearModel. Can this be done?

from knockback.

kmalakoff avatar kmalakoff commented on August 10, 2024

Most of the time the combination of model relationships or traversing the $data stack in the view using Knockout cover most cases.

I'm trying to think if there is a work around to pass the data through and the best I can think of is using a constructor for the view models. See create API examples like this and this. If you need this also for the model (non-collection) case, you can also look at the view model tests for create examples.

Basically, you have the option to use a create function install of passing a reference to the view model constructor in the factory. Then you can create an instance of your view model and pass whatever parameters you want to the constructor.

Would this work for you?

from knockback.

mlarsson avatar mlarsson commented on August 10, 2024

Yes that is exactly what I was looking for! Thank you.

from knockback.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.