knockout.js

Knockout model bindings not clearing when new model created

℡╲_俬逩灬. 提交于 2019-12-24 09:02:47
问题 I am creating a Knockout model within a bootstrap modal. Initially the model is created and bound to the template correctly, however when closing and reopening the modal I end up with multiple items in the template. The model doesn't seem to be re-instantiated with multiple modal.show() calls. I have broken down my real world example to that below with the same issues. Because of my real world code I call ko.cleanNode() to clear the bindings as without it I get the 'You cannot apply bindings

DevExtreme load JSON as datasource using knockout

╄→尐↘猪︶ㄣ 提交于 2019-12-24 08:38:56
问题 I'm new to both javascript and devextreme and currently finding my way through. I created a webpage which loads a json-file, which worked well, but I can't get it done using devextreme. I have a dxDataGrid which I want to contain the data. Using a .js-file, that data is also displayed correct. My json-file is this: { "user": [ { "id": 0, "name": "user0", "mail": "user0@example.com", "address": "examplestreet 0", "zip": "12345", "city": "examplecity", "country": "examplecountry", "dayOfBirth":

Twitter-Bootstrap Modal Bindinghandler with Knockout breaking if backdrop is clicked

醉酒当歌 提交于 2019-12-24 08:22:25
问题 I'm trying to disable the backdrop from closing the modal when clicked with the following: ko.bindingHandlers.showModal = { init: function (element, valueAccessor) { }, update: function (element, valueAccessor) { var value = valueAccessor(); if (ko.utils.unwrapObservable(value)) { $(element).modal({ backdrop: 'static', keyboard: true }); // this is to focus input field inside dialog $("input", element).focus(); } else { $(element).modal('hide'); } } }; From what I understand, $(element).modal

knockout js, add additional elements to an array

断了今生、忘了曾经 提交于 2019-12-24 07:59:47
问题 I have an app where I want to add extra elements to an item in an array, I have created a fiddle of what I'm trying to achieve. So the user starts the app, they click next fill in some details of an item and a description, they then should click next and fill in a price for the item(this is where I'm stuck). This example works up to a point, as in whenever I try and implement the price part I seem to be getting it wrong. You'll see once I click next the item is added to the array, however how

Knockout foreach not clearing previous entries on new VM

吃可爱长大的小学妹 提交于 2019-12-24 07:59:38
问题 I have a modal form with two nested lists bound to observable arrays. Each time I click the button to open the modal, these two nested lists aren't clearing their previous data, even through I generate a brand new viewmodel for the whole thing. I wind up with duplicated (and triplicated, etc...) items in these two lists. How can I ensure that when I give this thing a new viewmodel, it clears out the previous data? The ViewModel itself is fine: I can ko.toJS(self) that on each instance and

Knockout Validation isValid always returns true

冷暖自知 提交于 2019-12-24 07:46:23
问题 I am new to using knockout and I am trying to get the validation plug-in to work. However, IsValid is always returning turn. I have also tried ViewModel.errors().length == 0 but it is always zero Here is the rest of my code, please help. ko.validation.configure({ registerExtenders: true, messagesOnModified: true, insertMessages: true, parseInputAttributes: true, messageTemplate: null }); function ViewModel(survey) { // Data var self = this; self.ProjectNumber = ko.observable(); self

In a knockout custom binding, how do you know which value is triggering the update?

扶醉桌前 提交于 2019-12-24 07:45:25
问题 B"H I am working on an old project based on knockout js. I am trying to create a custom binding (for select2), but I am running into a brick wall trying to figure out which attributes (values) are the ones that changed. i.e how do I know whether the list of options have just changed? Or the selected value? If the list of values have just changed then I need to reconstruct the select2, an set the controls value to null (otherwise the first item is selected by default). If the user just

observable not defined inside object literal knockout

瘦欲@ 提交于 2019-12-24 07:37:17
问题 I have a observable defined inside a object literal of a knockout viewmodel . Now when I ran the application .Its unable to access the observable . $(function () { var viewModel = { Folders: ['Inbox', 'Archive', 'Sent', 'Spam'], Title: ko.observable("My View Model Test"), SelectedFolder: ko.observable(), Mails: ko.observableArray(), SelectedMail: ko.observable(), SelectedChoices: ko.observable(false), navigate: function (folder) { SelectedFolder(folder); $.ajax({ url: "/Api/MailBox", data: {

long ajax call breaking knockout binding

谁都会走 提交于 2019-12-24 07:31:35
问题 I am creating a personal website using durandal and knockout with the below code to bind a edit blog page. Everything worked great and I was able to bind the text area with the returned text of the ajax call. Once this was done I was curious if a long response from the webservice would break it, so I put in a Thread.Sleep(1000) into the service and now I cannot get it to bind the returned text to the text area. Any suggestions on how to get this to work??? side-note: I dont think this has to

multiple knockout bindings and sharing them

浪尽此生 提交于 2019-12-24 07:14:38
问题 So I have a scenario where I am have knockout binding on my main page. Index.cshtml: <div data-bind="foreach breadcrumbs"> <div> <script> var IndexViewModel = function () { var self = this; self.breadcrumbs = ko.observableArray(); }; ko.applyBindings(IndexViewModel); </script> And a Partial View that loads inside the Index.cshtml. The partial view has its own knockout bindings: <div id="someId"> </div> <script> var PartialViewModel = function () { var self = this; self.someFunction = function