knockout-mapping-plugin

Using updateFromJS is replacing values when it should be adding them

余生颓废 提交于 2019-12-02 18:51:38
问题 I have this code: var attachmentsModel = { convAttachments: ko.mapping.fromJS([]) }; $(function() { ko.applyBindings(attachmentsModel) refreshConvAttachments(); }); function refreshConvAttachments() { $.ajax({ url: '/xxxxxxx/', success: function (dataJS) { // Send KO the data ko.mapping.updateFromJS(attachmentsModel.convAttachments, dataJS); } }); } The AJAX call above returns: [{ "title": "BillGates", "added_by": "xxx", "thumb": "urlhere", "id": 410, "link": "/link/410", "added_on": "2011-02

Handling arbitrary options with metadata from server and ko.mapping create function

可紊 提交于 2019-12-02 16:29:22
问题 I have a view-model where some properties values available for selection are dictated by other properties, this is set via the requires field: var clusterOptions = [{ name: "None", sku: "0", price: 0, }, { name: "Standard MySQL Cluster", sku: "4101", requires: ["MySQL1"], price: 10, }, { name: "Enterprise MS SQL Cluster", sku: "4102", requires: ["402"], price: 5, }, { name: "NoSQL Sharding", sku: "4103", requires: ["403","404"], price: 10, }]; The code works (you can see how clicking

Performance tuning a knockout application - guidelines for improving response times

被刻印的时光 ゝ 提交于 2019-12-02 15:28:51
I have a large, complex page that relies heavily on knockout.js. Performance is starting to become an issue but examining the call stack and trying to find the bottlenecks is a real challenge. I noticed in another question ( Knockout.js -- understanding foreach and with ) that the accepted answer has the comment: ...and I suggest not using with where high performance is necessary because of the overhead... Assuming the statement is true, this is really useful stuff to know and I have not found a source for such performance tips. Therefore, my question is: Are there general guidelines / top

Using updateFromJS is replacing values when it should be adding them

倾然丶 夕夏残阳落幕 提交于 2019-12-02 10:26:23
I have this code: var attachmentsModel = { convAttachments: ko.mapping.fromJS([]) }; $(function() { ko.applyBindings(attachmentsModel) refreshConvAttachments(); }); function refreshConvAttachments() { $.ajax({ url: '/xxxxxxx/', success: function (dataJS) { // Send KO the data ko.mapping.updateFromJS(attachmentsModel.convAttachments, dataJS); } }); } The AJAX call above returns: [{ "title": "BillGates", "added_by": "xxx", "thumb": "urlhere", "id": 410, "link": "/link/410", "added_on": "2011-02-22T12:57:09-08:00" }, { "title": "biz-stone", "added_by": "xxx", "urlhere", "id": 411, "link": "/link

Handling arbitrary options with metadata from server and ko.mapping create function

时光毁灭记忆、已成空白 提交于 2019-12-02 07:44:59
I have a view-model where some properties values available for selection are dictated by other properties, this is set via the requires field: var clusterOptions = [{ name: "None", sku: "0", price: 0, }, { name: "Standard MySQL Cluster", sku: "4101", requires: ["MySQL1"], price: 10, }, { name: "Enterprise MS SQL Cluster", sku: "4102", requires: ["402"], price: 5, }, { name: "NoSQL Sharding", sku: "4103", requires: ["403","404"], price: 10, }]; The code works (you can see how clicking different options changes dependent options database and database clustering ): http://jsfiddle.net/g18c/DTdyM/

Knockout JS mapping plugin confusion

我的梦境 提交于 2019-12-02 03:07:14
I'm confused as to when and where I should declare my viewModel when using the mapping plugin. Here's my json file: { "members": [ { "memberid": "001", "membername": "Jason" }, { "memberid": "002", "membername": "Bob" } ] } Here's the html template: <div data-bind="foreach: members"> <h3 data-bind="text: memberid"></h3> <p>Name: <span data-bind="text: membername"></span></p> </div> Here is the rest: var data = $.getJSON("members.json",function(data) { var viewModel = ko.mapping.fromJSON(data); ko.applyBindings(viewModel); } ); ko.mapping.fromJSON(data, viewModel); Thanks in advance for your

Unable to map the Data using mapping plugin ? Knockout

…衆ロ難τιáo~ 提交于 2019-12-01 12:04:52
问题 I am trying to bind my data to view but i am unsuccessful in all my attempts . There is a Array of data i'm storing in a variable and later using mapping plugin and i am making those as observable's to bind it to view . Interesting thing here is i am getting no errors in console and i checked with <span data-bind="text: ko.toJSON(Item)"></span> I can see my array but i can't see it binded to view . Script code : console.log(ko.mapping.fromJS(jsonData)); var viewModel = new MainModel();

ko.mapping is undefined

与世无争的帅哥 提交于 2019-12-01 02:24:43
im following this example http://jsfiddle.net/rniemeyer/badZb/ . I just copy and paste the exact code into a sample application and it gave me this error : "ko.mapping is undefined" . Anyone know whats happening? My ko.observable and dependentObservable are working great, is just that ko.mapping is not working. FYI : The knockout.js version is 2.0 and Jquery 1.7.1 As the mapping plugin is exactly that, a plugin , it is not included in the core library. You need to include the mapping plugin separately. You can find it on GitHub . Just make sure you include it after including the core Knockout

ko.mapping is undefined

假如想象 提交于 2019-11-30 22:46:39
问题 im following this example http://jsfiddle.net/rniemeyer/badZb/ . I just copy and paste the exact code into a sample application and it gave me this error : "ko.mapping is undefined" . Anyone know whats happening? My ko.observable and dependentObservable are working great, is just that ko.mapping is not working. FYI : The knockout.js version is 2.0 and Jquery 1.7.1 回答1: As the mapping plugin is exactly that, a plugin , it is not included in the core library. You need to include the mapping

Knockout JS ObservableArray with many-to-many relationships

筅森魡賤 提交于 2019-11-30 15:43:40
I am creating a guest list app using Knockout.js, and so far things are going swimmingly. However I have a best-practices question. My app has several different types of objects: guests and tags among them. Guests can have multiple tags, and tags can have multiple guests. At different points in the app, I need to display both arrays individually. For example, I have a "Guests" view where one can see all the guests along with their associated tags, and I also have a "Tags" view where one can see all tags and their associated guests. At present, the code for me to add a tag to a guest looks