knockout.js

Identify the attribute change event in KnockoutJS?

自古美人都是妖i 提交于 2019-12-24 15:25:03
问题 Is there any way to Identify the attribute change event in KnockoutJS?? I found solutions in jQuery: firing event on DOM attribute change firing event on DOM attribute change But It would be good If I can do it with KO. Thanks. 回答1: If the attribute change is bound to a property in your view model, then you can simply subscribe to that property to get notified of changes. myViewModel.myProperty.subscribe(function(newValue) { alert("This property changed!!"); }); 来源: https://stackoverflow.com

How to use jquery ui with requireJS and knockout-sortable?

旧街凉风 提交于 2019-12-24 15:08:04
问题 I'm trying to use requireJS to manage dependencies in my first ever single-page javascript app. Having never used requireJS before, I'm struggling with something that I think is quit basic. My project uses knockoutJS, and an addon called knockout-sortable, which provides knockout bindings for the jquery ui 'sortable' plugin. It all works fine when I just load jquery ui, knockout and everything else without requireJS. My require main.js looks like this: require.config({ baseUrl: '/Scripts',

Problems with Knockout mapping when using object inheritance

强颜欢笑 提交于 2019-12-24 14:42:56
问题 Getting some weird behaviour I don't quite get when using the KO mapping plugin with subclassed objects. Use case: The server has a number of simple model classes used for the AJAX API. I want to generate a stub class that generates KO observables for properties on these classes, so that if I change the server code the stub classes are automatically updated with an observable for the new property - I need this so I can create brand new objects without mapping from existing data. I then want

how to access property in a observable

老子叫甜甜 提交于 2019-12-24 14:22:19
问题 I want to access the property in 'selectedCeremonyToUpdate()' observable whose property name is in 'name'. If 'name' contains 'City' then i want self.edit = function (data, event, name) { alert("In " + self.selectedCeremonyToUpdate().City()); } how to do this.. 回答1: You can access object properties by name using array semantics. Try this: self.selectedCeremonyToUpdate()[name]() 来源: https://stackoverflow.com/questions/14055594/how-to-access-property-in-a-observable

Encoded HTML in optionsText binding of knockout js

南楼画角 提交于 2019-12-24 14:18:14
问题 I am trying to create a dropdown list with html encoded options in knockout js using options binding. How can i decode the text returned from the function binded to the optionsText binding. <select data-bind="options: items, optionsText: function(item){ return "decoded text"}"></select> In general, I need a function that take a encoded html string and returns the decoded text. i.e. the function takes something like blah blah balh <sup>TM</sup> and return blah blah blah ™ 回答1: This will not be

KnockoutJS Mapping Plugin (observableArray)

可紊 提交于 2019-12-24 14:18:03
问题 I am new to knockout and I am having a problem with using the mapping plugin as I do not understand how it maps my JSON data. This is a sample json data similar to what is in my program: contact: { name : 'John', email : 'address@domain.com', phones : [{ phoneType : 'Home Phone', phoneNumber: '999-888-777'}, { phoneType : 'Business Phone', phoneNumber: '444-888-777'}, }] } As you can see, this json data contains an array of phones. I used knockout mapping plugin and I can bind the 'name',

Knockout UNable to Bind $root

孤人 提交于 2019-12-24 14:05:23
问题 Inside my Document i've added <div data-bind="text: ko.toJSON($root)"></div> to my html5 page. Unfortunately IE8 gives me an Error 'Unable to apply binding to $root' or similar. No Problems on FF and Chrome. How can i retuen a json dump of my current viewmodel for debugging needs? 回答1: I was able to repro your issue: the problem isn't with your binding but with the ko.toJSON call. Knockout uses the JSON.stringify function internally which fails in your case. Altough Is JSON.stringify()

Not able to trigger Knockout data-bind using jQuery

喜你入骨 提交于 2019-12-24 14:04:00
问题 I am writing a plugin using jQuery and knockout. I have two radio buttons. I am using knockout data-bind to check and uncheck the radio button. The problem is that when I am trying to uncheck the radio button on click of another button using jQuery, it is not updating bind observable property . <input type="radio" data-bind="checked: selectedVal" name="1" value="fixedPrice"/> Fixed Price <input class="hn" type="radio" data-bind="checked: selectedVal" name="1" value="allowBiding"/> Allow

Updating Change Knockout Multiselect value from jQuery

走远了吗. 提交于 2019-12-24 13:23:14
问题 I'm working on making a few tweaks to a project that uses Knockout, and I can't for the life of me figure out how to update the value of a multiselect from jQuery. I'm sure there's ways to do it natively in Knockout, but it's a tiny change and I really don't want to have to dig into it. The html for the select box is this: <select id="projectSelect" data-bind="multiSelect: { items: projects, value: filteredProject, header: false, multiple: false }, optionsText: 'name', optionsValue: 'id',

Validate observables within a collection using Knockout Validation

孤者浪人 提交于 2019-12-24 13:19:28
问题 I have a message field and collection of people being bound in an unordered list accompanied each with a drop down list of colors and a default selection. Validation on the message field works, erase the text and an error is displayed and the error count increases. However, when you change one of the drop down entries to "Choose.." (effectively unselecting the option), you receive a "this field is required" message correctly however the errors object does not appear to be updating. It must