knockout.js

inserting dynamic html into durandal views

╄→尐↘猪︶ㄣ 提交于 2020-01-15 10:43:17
问题 I am dynamically inserting html in durandal views but it does'nt work can any one help me out in that? my sample html is in durandal view <div data-bind="foreach:arrayofmodels"> <div data-bind="html:dynamichtml"/> </div> in my model(not view model) which is going to insert dynamic html dynamichtml(<span data-bind="click:Mymodelclickfunction"/>); in my viewmodel var arrayofmodels=ko.observableArray(); vm={ arrayofmodels:arrayofmodels; } return vm; there is a separate function to get list of

Check duplicate using ko.observableArray

落爺英雄遲暮 提交于 2020-01-15 09:46:27
问题 How can I check the duplicate signatures before adding. In the below scenario, I wanted add signature if no signature found the list. var Signature = function (name, interestDeclared) { this.Name = ko.observable(name); this.RelevantInterest = ko.observable(interestDeclared); } viewModel = { signatures: ko.observableArray([]), addSignature: function () { var name = $('#signatureName').val(); var intd = $('#interest').is(':checked'); this.signatures.push(new Signature(name, intd)); },

Getting selected value from dropdown list in Knockout.js

旧时模样 提交于 2020-01-15 09:19:08
问题 I am new to knockout, and have a problem getting a selected value from dropdown list. I tried to change value to ' selectedCity ' and I am getting [Object object] . Thanks! My HTML <select data-bind="options: Cities, optionsText: 'CityNameRu', value: selectCity"> </select> <span data-bind="text: selectedCity"></span> Knockout function CityModel(data) { var self = this; this.CityId = ko.observable(data.CityId); this.CityNameRu = ko.observable(data.CityNameRu); this.CityName = ko.observable

Knockoutjs: refresh bindings after populating select list

拟墨画扇 提交于 2020-01-15 07:39:31
问题 I feel like this must have been asked before, but I've looked at Knockout JS binding initial value of dropdown list Knockout does not sync manual set of option's selected attribute How to pre-select an option in a dropdown knockout js and How to set initial values for Knockout's observables (for cascading lists)? But those problems weren't quite the one I'm facing. In my view I receive a viewmodel from an ajax call. In that object is a country ID. In a subsequent ajax call, I retrieve a list

splice() not updating items order of array within knockout.js

柔情痞子 提交于 2020-01-15 06:42:52
问题 Following a prior post on how to update the order of an array. I followed the suggestion of Michael Best and used splice() to modify the ordering of my array on button click self.moveup = function (itemIndex) { var i = self.itemList.indexOf(itemIndex); if(i >= 1){ var array = self.itemList(); self.itemList.splice(i-1, 2, array[i], array[i-1]); } Where I am having trouble is in incrementing the items in the array. From reading the usage of Array Splice The first param indicates where the

splice() not updating items order of array within knockout.js

試著忘記壹切 提交于 2020-01-15 06:42:07
问题 Following a prior post on how to update the order of an array. I followed the suggestion of Michael Best and used splice() to modify the ordering of my array on button click self.moveup = function (itemIndex) { var i = self.itemList.indexOf(itemIndex); if(i >= 1){ var array = self.itemList(); self.itemList.splice(i-1, 2, array[i], array[i-1]); } Where I am having trouble is in incrementing the items in the array. From reading the usage of Array Splice The first param indicates where the

Refresh masonry layout after knockoutJS databound template is inserted into a container

[亡魂溺海] 提交于 2020-01-15 06:05:08
问题 I have a knockout template binding used to bind list of divs to an observable array: <div class="menu-instance-entries js-masonry" data-masonry-options='{ "gutter": 20, "itemSelector": ".menu-entry" }' data-bind="template: { name: 'menu-entries-template', foreach: MenuEntries }"></div> MenuEntries is an observable array that gets a new element " push ed" into it by a click handler bound to a view model's function. The layout of the elements in the .menu-instance-entries container is

Remove knockout js bindings on cloned element

﹥>﹥吖頭↗ 提交于 2020-01-15 05:45:45
问题 I am using the knockout js template binding functionality to render a collection of items to an element: <script type="text/javascript"> ko.applyBindings(new function () { this.childItems = [{ Text: "Test", ImageUrl: "Images/Image.png" }]; }); </script> <script type="text/html" id="template"> <div class="childItem" data-bind="attr: { title: Text }"> <img data-bind="attr: { src: ImageUrl }" /> </div> </script> <div class="childSelector" data-bind="template: { name: 'template', foreach:

Knockout - How to bind outer container css from set of checkboxes?

£可爱£侵袭症+ 提交于 2020-01-15 04:05:26
问题 OK, admittedly horrible grammar in the question, but here's the lowdown: I'm using the following in my site: Twitter Bootstrap Knockout Durandal I'm trying to add a css class to the outer label surrounding a checkbox (in a list of checkboxes) so it can highlight the selected checkboxes. Essentially the code is this: <div data-bind="foreach:values"> <label class="checkbox inline btn" data-bind="css: { }"> <input type="checkbox" data-bind="attr: { value: text }, checked: $parent.checkedValues"

Knockout custom binding handlers: $root is undefined

二次信任 提交于 2020-01-15 03:32:16
问题 I am using a Knockout Custom Binding handler (borrowed from Creating groups with Knockout.js foreach). Within the nested markup, I'd like to reference an observable that is located on the root of the view model. However the binding fails because $root is undefined. The same markup works fine with a standard foreach binding. I don't know why the custom hander prevents using $root. Here is the source for the binding handler : ko.bindingHandlers.foreachGrouped = { init: function(element,