knockout.js

Changing parts of view dynamically based on controller response

[亡魂溺海] 提交于 2020-01-01 09:36:10
问题 I'm looking for best approach suggestions for the below scenario: A user can choose one or more csv files to validate(Attachment 1) which on "validate" button click goes through the validation code(showing progress bar till it returns an output). A return response is either a success message or the error details for each file chosen to validate(Attachment 2) A successfully validated file can now be uploaded to azure storage with an "Upload" button. Attachment 1 Attachment 2 Now, to make

jQueryUI Spinner widget with knockout

余生颓废 提交于 2020-01-01 08:50:58
问题 How can I use a jQuery UI Spinner widget in Knockout bound input? <tbody data-bind="foreach: orders"> <tr> <td data-bind="text: Name"></td> <td><input type="number" style="width: 100px;" data-bind="value: Price" /></td> <td><input type="number" style="width: 50px;" data-bind="value: VAT" /></td> <td><input type="number" style="width: 50px;" data-bind="value: Number" /></td> <td data-bind="text: Final()"></td> <td><a href="javascript:void(0);" data-bind="click: $root.removeOrder">Remove</a><

ko.observableArray support for associative arrays

狂风中的少年 提交于 2020-01-01 08:03:59
问题 Is there a better (built in?) way to mix observableArray and associative arrays? viewModel = { a: ko.observableArray(), a_assoc: {}, add_item: function(i) { if (typeof this.a_assoc[i] == 'undefined') { this.a.push(i); this.a_assoc[i]=1; } } } viewModel.add_item('bla'); 回答1: Typically, you would do something like this in Knockout: var viewModel = { a: ko.observableArray(["a","b","c","d"]), add_item: function() { this.a.push("new" + this.a().length); } }; viewModel.a_assoc = ko

KnockoutJS JQuery Combobox Binding

大城市里の小女人 提交于 2020-01-01 06:19:14
问题 I'd like to make a binding for knockout which uses the JQuery Autocomplete Combobox and allows for 2 way binding. http://jsfiddle.net/rniemeyer/PPsRC/ from this question has gotten a start, but doesn't fully implement the combobox functionality as on the jQuery demo site. (ie. selection highlighting, button styling, button not submitting the form, etc.). 回答1: This is a bit late, but I have a two way autocomplete combo box binding in my Knockout UI library (see Dropdown). Take a look and see

KnockoutJS JQuery Combobox Binding

て烟熏妆下的殇ゞ 提交于 2020-01-01 06:19:13
问题 I'd like to make a binding for knockout which uses the JQuery Autocomplete Combobox and allows for 2 way binding. http://jsfiddle.net/rniemeyer/PPsRC/ from this question has gotten a start, but doesn't fully implement the combobox functionality as on the jQuery demo site. (ie. selection highlighting, button styling, button not submitting the form, etc.). 回答1: This is a bit late, but I have a two way autocomplete combo box binding in my Knockout UI library (see Dropdown). Take a look and see

Best way to get only modified rows from observableArray (when there is bulk edit option)

独自空忆成欢 提交于 2020-01-01 05:50:15
问题 I have an ObservableArray collection which binds to the HTML table with bulk edit option (MVC3), every time the user hits commit I wanted to send only the modified rows from the collection instead of sending entire viewmodel list, please advise if any best way to track or filter only the modified rows. 回答1: Here is a post about creating a dirty flag in Knockout that will track changes to all observables in an object. Typically, you would add a dirty flag to each item in your array in a

KnockoutJS: click event invoked on every Option in Select

独自空忆成欢 提交于 2020-01-01 02:11:46
问题 I want Knockout to call an event whenever the user clicks an option in a SELECT element. Here's my JavaScript: function ReservationsViewModel() { this.availableMeals = [ { mealName: "Standard (sandwich)", price: 0 }, { mealName: "Premium (lobster)", price: 34.95 }, { mealName: "Ultimate (whole zebra)", price: 290 } ]; } ko.applyBindings(new ReservationsViewModel()); Here's my HTML: <select data-bind="foreach: availableMeals"> <option data-bind="text: mealName, click: alert('hello')" /> <

How to conditionally render a css class with knockoutjs

家住魔仙堡 提交于 2020-01-01 01:16:31
问题 I have some html like the following: <div class="control-group"> <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" /> </div> However, ifnot: $data.DealCodeIsValid , I need to render the following: <div class="control-group error"> <input type="text" data-bind="value: $data.DealCode" name="DealCode" class="input-mini" /> </div> Note the additional class "error" in the div. Is there a way to do that with knockoutjs? 回答1: Something like <div data-bind="css:

Using Knockout to Populate Bootstrap Rows and Spans

佐手、 提交于 2019-12-31 16:43:29
问题 Well essentially I'm trying to populate a Bootstrap template via Knockout and a JSON object. Bootstrap scaffolding: <div class="row-fluid"> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> </div> <div class="row-fluid"> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App

Using Knockout to Populate Bootstrap Rows and Spans

拥有回忆 提交于 2019-12-31 16:42:18
问题 Well essentially I'm trying to populate a Bootstrap template via Knockout and a JSON object. Bootstrap scaffolding: <div class="row-fluid"> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> </div> <div class="row-fluid"> <div class="span4"> <h1>App Title</h1> <p>App Description</p> </div> <div class="span4"> <h1>App Title</h1> <p>App