knockout.js

knockout mapping with computed fields

旧街凉风 提交于 2019-12-18 12:37:05
问题 I'm getting data from a WCF service,and i map, and bind the data with my DOM object : var PayinyVM = {}; $.getJSON('/service/PaidService.svc/PaidList', function (data) { var tmp = JSON.stringify(data.d); PayinyVM.model = ko.mapping.fromJSON(tmp); ko.applyBindings(PayinyVM); }); the result is shown as excepted on my DOM bind it to model. What I couldn't find out is how to add some computed observable let's say my data is returning people with FirstName and LastName, how can I make a computed

Using an external Template in KnockoutJS

与世无争的帅哥 提交于 2019-12-18 12:24:18
问题 is it possible to use an external Template in KnockoutJS like this? <script type="text/html" id="a_template" src="templates/a_template.html"> </script> I've tried this solution but didn't get it working. 回答1: You could also look at: https://github.com/ifandelse/Knockout.js-External-Template-Engine 回答2: You can use jquery to dynamically load html into a script element, and then execute knockout based on that. <script type="text/html" id="template_holder"></script> <script type="text/javascript

Bootstrap's tooltip not working with knockout bindings? (w fiddle)

五迷三道 提交于 2019-12-18 11:47:12
问题 Fiddle: http://jsfiddle.net/LkqTU/9399/ Code: var ViewModel = function (first, last) { var self = this; self.showIcon = ko.observable(false); self.triggerIcon = function () { self.showIcon(true); }; }; $('.card-delete-button').tooltip({ 'placement': 'top', 'title': 'Text' }); ko.applyBindings(new ViewModel("Planet", "Earth")); For some reason the tooltip isn't showing up for the '.card-delete-button'. I think it's because that DOM element isn't available until the triggerIcon function is hit.

Knockout + Jquery Validate

橙三吉。 提交于 2019-12-18 10:53:12
问题 I'm trying to setup validation with jquery validate, and i've got the viewmodel coming back from the server, mapped to the client and successfully have knockout js binding some data. I included a called to validate but the validation never triggers, however if I put a class on the input box and then call valid it triggers as expected. Any ideas? <script type="text/javascript"> var viewModel; $(document).ready(function () { $.ajax({ url: 'Home/GetUserData', type: 'post', success: function

KnockoutJS catch errors Binding

被刻印的时光 ゝ 提交于 2019-12-18 10:31:41
问题 I want to catch an error, correct it and continue executing the program. http://jsfiddle.net/Gthv9/12/ But, I can't do it! If you click on: "re Check On Model1", "re Check On Model3" - it's ok. If you click on: "re Check On Model1", "re Check On Model2", "re Check On Model3" - there's an error. Uncaught Error: Unable to parse bindings. Message: ReferenceError: name3 is not defined; Bindings value: text: name3 Why? I wrapped the problem code in a try-catch block (viewModel.recheckData2() ),

KnockoutJS catch errors Binding

你。 提交于 2019-12-18 10:31:25
问题 I want to catch an error, correct it and continue executing the program. http://jsfiddle.net/Gthv9/12/ But, I can't do it! If you click on: "re Check On Model1", "re Check On Model3" - it's ok. If you click on: "re Check On Model1", "re Check On Model2", "re Check On Model3" - there's an error. Uncaught Error: Unable to parse bindings. Message: ReferenceError: name3 is not defined; Bindings value: text: name3 Why? I wrapped the problem code in a try-catch block (viewModel.recheckData2() ),

Is it possible to data-bind visible to the negation (“!”) of a boolean ViewModel property?

跟風遠走 提交于 2019-12-18 10:27:23
问题 I'd like to use a property on my ViewModel to toggle which icon to display without creating a separate computed property of the inverse. Is this possible? <tbody data-bind="foreach: periods"> <tr> <td> <i class="icon-search" data-bind="visible: !charted, click: $parent.pie_it"></i> <i class="icon-remove" data-bind="visible: charted, click: $parent.pie_it"></i> </td> </tr> </tbody> My ViewModel has a property periods which is an array of month, like this: var month = function() { this.charted

Is it possible to data-bind visible to the negation (“!”) of a boolean ViewModel property?

纵然是瞬间 提交于 2019-12-18 10:27:21
问题 I'd like to use a property on my ViewModel to toggle which icon to display without creating a separate computed property of the inverse. Is this possible? <tbody data-bind="foreach: periods"> <tr> <td> <i class="icon-search" data-bind="visible: !charted, click: $parent.pie_it"></i> <i class="icon-remove" data-bind="visible: charted, click: $parent.pie_it"></i> </td> </tr> </tbody> My ViewModel has a property periods which is an array of month, like this: var month = function() { this.charted

Access $parent's $parent in knockout view - nesting context

半腔热情 提交于 2019-12-18 10:24:59
问题 Updated for brevity How can I reference the $parents' $parent in nested Knockout foreach / with bindings? Example - <!-- ko foreach: grandParent --> <tr> <!-- ko foreach: $parent.parents --> // <-- Doesn't work <!-- ko foreach: children --> <td data-bind="if: favToy().name == $parent.$parent.favToy().name"> <span data-bind="text: favToy().name"></span> </td> <!-- /ko --> <!-- /ko --> </tr> <!-- /ko --> Original Sorry for the confusing question but I am trying to reach a second level parent's

Are there any knockoutjs page/routing frameworks?

邮差的信 提交于 2019-12-18 10:07:24
问题 Coming from asp.net MVC 3. In MVC4 they introduced WebAPI's. It would be nice to be able to do all view/routes code in javascript and just rely on MVC for API. Heck it's really cool that webapi's can be run independent of IIS! That being said: Are there any page frameworks that can leverage KnockoutJS which are similar to my mock-up below: Framework.RegisterRoutes(..,mainViewModel);//sets the CurrentViewModel? Each route being a separate file of a viewModel, and a view to be injected into the