0

I'm trying to understand the knockout syntax and have the following question.

If I have the following view-model

var anotherObservableArray = ko.observableArray([
    { name: "Bungle", type: "Bear" },
    { name: "George", type: "Hippo" },
    { name: "Zippy", type: "Unknown" }
]);

the Array should be empty and not contain the hardcoded value as above.

I wants to populate this using jquery with this code

$.getJSON('api/market', self.markets);

How can i do that, and where should this getJSON code go? Can anyone help me with a example?

1 Answer 1

1

You can check out the documentation

but basically it should look like this

$.getJSON("/some/url", function(data) { 
    anotherObservableArray(data);
})

assuming the data is a json array, otherwise set the observable to something like data.arrayProperty or whatever the array is stored as

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.