knockout-mapping-plugin

Knockout create array in viewmodel

只谈情不闲聊 提交于 2019-12-13 03:51:23
问题 another knockout question. I've a page where serversided paging is desirable. I wanna achieve this using knockout. I Create a viewmodel using the mapping pluging and added lots of functionality. var jsonModel = '@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(this.Model, new Newtonsoft.Json.Converters.IsoDateTimeConverter()))'; myViewModel = ko.mapping.fromJSON(jsonModel, {}, new ViewModel()); ko.applyBindings(myViewModel); I've implemented a computed observable at first. But this gave

getting multidimensional array (object) observable in KnockoutJS

扶醉桌前 提交于 2019-12-12 22:15:22
问题 I am building an application with Knockout and find it very useful. Although, I have a problem with getting multidimensional array (object) observable. At the moment I am using following structure: self.form = ko.observableArray(ko.utils.arrayMap(initialData, function(section) { var result = { name : section.name, code : section.code, type : section.type, fields: ko.observableArray(section.fields) }; return result; })); It works well, but I can't get it working if the initialData is more than

Can't map JSON object to ViewModel (knockout js)

本秂侑毒 提交于 2019-12-12 20:42:17
问题 I'm receiving json data from WCF service and want to map it to my viewModel. JSON DATA: {"bios" : { "Caption" : "something", "Version": "something else", .... } } My HTML part is the following: <ul class="biosContentUL"> <li class="biosContentLI"> <p> <b>Caption: </b><span data-bind="text: bios.Caption"></span> </p> </li> <li class="biosContentLI"> <p> <b>Version: </b><span data-bind="text: bios.Version"></span> </p> </li> ....... </ul> My ViewModel is the following: var viewModel = { bios:

Knockout ViewModel isValid error when using Knockout validation plugin

房东的猫 提交于 2019-12-12 12:19:49
问题 I'm new to using knockout and I'm trying to use the knockout validation plugin along with the mapping plugin. I'm having an issue with the isValid function on the view model object. According to the documentation isValid should return a bool to determine whether any of the observables on the view model are in valid but when I call it I get an error saying that isValid is not a function. However if I call isValid on the observables themselves it works fine. The problem is I'm using the mapping

Knockout.js ko.mapping.toJS not refreshing data in my view

若如初见. 提交于 2019-12-12 10:44:03
问题 I fetch a json object from the server and populate my view. I then change the data, push it back to the server. I then fetch a new copy of the data hoping it will refresh my view with any changes. However that doesn't happen. TIA $(document).ready(function() { var customer_id = get_customer_id(); var data = load_model(); contract_model = ko.mapping.fromJS(data,{}); ko.applyBindings(contract_model); } function load_model(){ var url = '/ar/contract_json?contract_id='+get_contract_id(); var data

Template for a single dimension array with Knockout.js and ko.mapping

末鹿安然 提交于 2019-12-12 03:17:59
问题 I have a JSON string that I am mapping with ko.mapping plugin and I need to create observable bindings for one of the mapped arrays. The array is in the JSON as [1,2,3,4,5] so it has no index. I have the following code working to a certain point: <script id="statRowTemplate" type="text/html"> {{if type() != "column"}} <tr> <td><label>Name: </label><input data-bind="value: name" /></td> <td><label>Plot Points: </label><ul data-bind="template: {name: 'dataTemplate' , foreach: data}"></ul> </td>

Update an Input Box's text on a click inside the viewmodel - knockout

泄露秘密 提交于 2019-12-12 02:58:25
问题 I have a question regarding updating currently bound nested viewmodels and that is related to my last question here. This is for a test where I added a simple Input box to sample my current problem. The problem is: ViewModel is bound inside a template(Don't think the sample should necessarily be) On a button click we want to update the Input Box located inside it, The input box won't be updated, I did getting reports by console and seems the data is changed. What is your idea, Fiddle is

overriding a JSON property to be computed

 ̄綄美尐妖づ 提交于 2019-12-12 00:27:50
问题 I am brand spanking new to knockout.js so forgive if this is a trivially easy question. I am getting JSON data from a web service that already contains a property that needs to be computed. Something like { ValueA: 1, ValueB: 3, SumOfValues: 0 } SumofValues needs to be the sum of ValueA and ValueB. I want to use the mapping plugin to create my viewmodel, but override the creation of SumOfValues so that it is computed. When the Viewmodel is converted back into JSON data (for posting back to

Update part of mapped ko model

蹲街弑〆低调 提交于 2019-12-11 23:34:42
问题 How can I just update one part of a mapped model? var model = { foo: { bar: "hello" }, moo: { la: "world" }}; var mapped = ko.mapping.fromJS(model); Mapping results in: mapped = { __ko_mapping_object__ : object, foo: { bar : function c() }, moo: { la: function c() }, __proto__ : object } Since foo and moo aren't observable, if I do: mapped.foo = { "bar" : "changed" }; or mapped.foo = ko.mapping.fromJS({ "bar" : "changed" }); The object is updated but rebinding is not triggered. Any ideas? I

can't resolve knockout js with nested objects

被刻印的时光 ゝ 提交于 2019-12-11 23:31:32
问题 i'm trying to learn knockoutjs and can't figure out how the children observable works! i've tried reading many articles and many problems even on SO but probably missing something somewhere. my json structure is (generated by Rails json renderer): Albums -> Tracks -> Metadata Album -Track --Metadata -Track --Metadata Album -Track -- Metadata etc. My view's are nested as well. In a page, each album goes under a div and each track goes under table row in the above div. My View and JS codes are