knockout.js

Programmatically apply Knockout bindings to specific tags within a text block

巧了我就是萌 提交于 2019-12-22 18:13:23
问题 I have a block of html markup that I'd like to databind to a div using Knockout JS. This is simple enough with the knockout html binding. What I'd like to do is conditionally bind child elements within that html markup, based on their class. These elements can appear anywhere within the html markup, as they are inline elements (like span , a tags, etc). The purpose of this is to databind click events to specific words or phrases within this text block, so that I can call a function (in this

How to export a HTML table to Excel supported by Chrome and IE?

▼魔方 西西 提交于 2019-12-22 13:52:18
问题 On my MVC project I have a HTML table bound with Knockout. I'm trying to Export the table to Excel. I tried on client side with JavaScript: self.exportToExcel = function () { javascript: window.open('data:application/vnd.ms-excel,' + $("#tableToprint").innerHTML()); } OR: var tableToExcel = (function () { var uri = 'data:application/vnd.ms-excel;base64,' , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3

Knockout JS Update Color

落花浮王杯 提交于 2019-12-22 13:49:31
问题 I'm using Knockout observables to update span values located within table cells. I need to change the background color of the table cell when the new value is different from the old value. It seems when i subscribe to the observable i do not have access to the old value during an update. Is there a way to get the old value? I was planning to update the table cell background using the css binding with a state observable. <td data-bind="css: { tempIncreased: tempState() > 0 }"> <span data-bind=

Does conditional logic work under the default knockout.js 2.0 template engine?

心不动则不痛 提交于 2019-12-22 12:29:07
问题 The conditionals below arent working with my default template with knockout.js 2.0. It just writes out the IF statements. <span data-bind="foreach: admin.home.paging.pages"> {{if $data == app.viewModel.admin.home.paging.page()}} <span data-bind="html: $data"></span> {{else}} <a href="#" data-bind="click: app.viewModel.admin.home.paging.searchByPage($data), html: $data"></a> {{/if}} </span> UPDATE I did the following instead. <span data-bind="foreach: admin.home.paging.pages"> <span data-bind=

knockout javascript foreach binding

我只是一个虾纸丫 提交于 2019-12-22 10:55:08
问题 I'm trying to allow a user to create a casting and add an array of categories to this casting object. I was trying to use knockout's foreach binding to the array of categories and let users add new categories to the casting. I have created a jsfiddle to illustrate what I'm trying to explain here. http://jsfiddle.net/msell/ueNg7/16/ The JSON object gets built up correctly as a user modifies a casting, but I cant quite get the list of castings to display. 回答1: You have several problems: You are

Knockout js lots of custom bindings

做~自己de王妃 提交于 2019-12-22 10:38:00
问题 What would be considered a good way of handling lots of custom bindings with the possibility that the binding is not present? Say my html expression binds to image_url as below. <span title="Company Logo" data-bind="image_url: company_banner"></span> However there is every possibility that the image_url binding is not available. In that case scenario, I'd just like to return a string value of company_banner. Normally one would add a custom handler like below but if that handler is not

KnockoutJS - Nested Data, Loading Children

点点圈 提交于 2019-12-22 10:37:13
问题 I am very very new to knockoutjs - having worked through the tutorials and I have made a nice start. I have application which seems well suited to KO. In that I need to populate a table with data from JSON. This data is nested, and can be nested at any depth, but my API will only ever return data two levels deep. E.g. Node 1 Node A Node B I've managed to get the data to load into my table, lovely. I've taken this a step further and have supported nesting. I have a requirement so that if a

knockout js custom binding called after internal dom elements rendered

柔情痞子 提交于 2019-12-22 09:58:41
问题 I am not sure if i am going about this in entirely the wrong way! But I would like to be able to call a custom binding on an element after all code within it has been executed. I have tried a number of ways: template and if bindings with afterrender, and a custom binding, but due to the fact that the content within the element uses foreach the all the bindings that i have tried call call my method before the dom element that the foreach will render has run. the only option i can think of is

NewtonSoft Json DeserializeObject empty Guid field

安稳与你 提交于 2019-12-22 09:47:36
问题 I'm using ASP.NET MVC C# with HTML CSS jQuery KnockoutJs frontend. I have a modal contact form on my HTML page. The idea is that if I create a new contact the modal form pops up with blank values including a blank hidden id field. If I edit a contact then the modal form pops up with filled out fields including that hidden id field. In my controller I intend to do this: public JsonResult Contact(string values) { var contact = JsonConvert.DeserializeObject<contact>(values); if (contact.Id

Why is one ko.mapping.fromJS working and other one not?

僤鯓⒐⒋嵵緔 提交于 2019-12-22 09:35:32
问题 I have a class a class named Foo and Foo contains Model. I am doing a ko.applyBinding on Foo. The Foo class has a function which retrieves JSON from server and then I do: self.Model = ko.mapping.fromJS(result); where self is instance of Foo and result is JSON. This works 1st time. However, when 2nd item I retrieve data from server it just doesn't work. But if the above line to: self.Model = ko.mapping.fromJS(result, {}, self); it works. Can anybody tell me why is the 1st one not working and