knockout.js

selected object pattern with knockout

一个人想着一个人 提交于 2020-01-02 14:06:24
问题 Does anybody know how I'd accomplish the following pattern with knockoutJS? I use this pattern all the time in apache flex and want to see if I can mimic it. I am unsure how to replace an observable with another. Any help/thoughts much appreciated. //model myViewModel = { items : ko.observableArray(), selected_item : ko.observable() } //view <h3 data-bind="text : myViewModel.selected_item.name"> </h3> <ul> <!-- ko foreach: myViewModel.items --> <li data-bind="text : name"/> <!-- /ko --> </ul>

How to reset knockout bindings in Jasmine test

送分小仙女□ 提交于 2020-01-02 10:37:19
问题 I'm trying to write test for knockout feature with jasmine as below and I'm getting following error: Error: You cannot apply bindings multiple times to the same element. describe("ThreeStepNavigationView", ()=> { var testSubject; var SmallNavigationStates = ['ribbon','expanded']; var ExtraSmallNavigationStates = ['collapsed','ribbon','expanded']; beforeEach(()=> { loadFixtures('SidebarAndSiteHeader.html'); testSubject = new Mobile.Navigation.ThreeStepNavigation.View(); ko.applyBindings

unable to parse bindings for nested knockout bindings

末鹿安然 提交于 2020-01-02 10:18:57
问题 I created two sub divs inside main div and based on radio button selection, div is shown and hidden. Now , inside one of the sub div i created one dropdown and used foreach binding to populate it.Now when i am running , list of items are coming but show and hide functionality stopped working and in console it is shown as "unable to parse binding" of foreach. Kindly help me in resolving the issue. sample code is present below : HTML FILE <body> <div id="selectdiv"> <input type="radio" id=

Knockout.js: clear selection in select element

℡╲_俬逩灬. 提交于 2020-01-02 08:58:25
问题 I need to clear the selection from a <select> element. I've already read such posts as Knockoutjs clear selected value in combobox and have tried the accepted answers, but those solutions don't seem to be working (don't know if something has changed in Knockout 2 since the answer was accepted?). Here's an example view model: var ClearSelectionViewModel = function () { var self = this; self.station = ko.observable(); self.selectedStation = ko.observable(); self.selectedStation.subscribe

jQuery Mobile with KnockoutJS ListView Issue

你离开我真会死。 提交于 2020-01-02 07:59:09
问题 This example of what I am trying, the listview doesn't end up with nice looks, Can anyone please suggest what I am doing wrong. this is happening specifically on data-inset=true. http://jsfiddle.net/xQ9Uu/1/ if I set like this, its ok but its not really the list. <ul id="alarmslist" data-bind="foreach: days" data-role="listview"> making the data-inset true breaks the design. <ul id="alarmslist" data-bind="foreach: days" data-inset="true" data-role="listview"> Thanks In Advance. 回答1:

Dynamically enable/disable kendo datepicker with Knockout-Kendo.js

被刻印的时光 ゝ 提交于 2020-01-02 07:45:23
问题 I'm trying to enable / disable a kendo datepicker based on the selected value of an select using Knockout-Kendo.js. The HTML: <select data-bind="value: test"> <option value="1">1</option> <option value="2">2</option> </select> <input data-bind="kendoDatePicker: {value: date, enabled: test() == 2}" /> The JS: ko.applyBindings({ date: ko.observable(), test: ko.observable(), }); The fiddle: http://jsfiddle.net/xTjqH/2/ It does initially disable the datepicker, but it wont enable it once "2" is

Shopping Cart logic (?) trouble with KnockoutJS

好久不见. 提交于 2020-01-02 07:29:20
问题 The Goal Make a dynamic list of products. The Scenario I have a shopping application with products. When I click on the add button of a product, I want to display in the sidebar, the product what I have added. Summarized Problem (You just need to read this) I have the following code in my ProductsSummary/Index.cshtml (using Razor Engine): <ul class="summary"> @if (Session["ProductsSummary"] == null) { <li class="is-empty"> <p>Your summary is empty.</p> </li> <li data-bind="attr: { 'data

Throttling with knockout mapping plug

你离开我真会死。 提交于 2020-01-02 07:24:06
问题 I'm having a problem with the knockout-mapping plugin with IE8. Our situation is that we send over all the possible records that can be displayed to the client. Then we handle all paging and filtering on the client side for a responsive system. Currently, we are sending of a list of 250 records to display in a jQuery template based grid via jQuery ajax. When we call ko.mapping.fromJS (not the fromJSON function) to map the objects, we are getting a "Script taking too long" message from IE8.

Use KnockoutJS ViewModel in External JavaScript File

China☆狼群 提交于 2020-01-02 06:09:30
问题 How do you create a KO.JS ViewModel in an external JS file then use it in an html file? This seems like such a simple thing but I cannot get it to work and cannot find any clear information on how to do this. If I have overlooked I apologize and will remove this if someone can point me to the answer. EXTERNAL vm: var myApp = (function (myApp) { myApp.ReportViewModel = function() { var self = this; self.test = ko.observable(); } }(myApp || {})); Seperate HTML File: <!DOCTYPE html> <html> <head

knockout.js recursive binding

…衆ロ難τιáo~ 提交于 2020-01-02 04:51:26
问题 I'm trying to do some complex binding with knockout (at least for a newbie like me). Consider the following data: var originalData = { id: 1, name: "Main", children: [ { id: 2, name: "bob", children: []}, { id: 3, name: "ted", children: [{id: 5, name:"albert"}, {id: 9, name: "fred"}]} ], selectedChild: { id: 2, name: "bob" } }; <table> <tr> <td data-bind="text: name"></td> </tr> <tr data-bind="if: children().length > 0"> <td> <select data-bind="options: children, optionsText: function(item){