How to create a MySQL database connection in javascript of Knockout.js file?

I have created the following table in MYSQL and a file in Knockout.js.I want that the data we are entering in the Knockout.js through variable pf should be stored in the table “PORTFOLIO”.The database connection I want to implement is through javascript only.I tried creating a database connection between MYSQL and Knockout.js but was not successful.Kindly help.

 //TABLE
CREATE TABLE PORTFOLIO
  (
  ID INT NOT NULL,
  pf VARCHAR (255)
  );

File in Knockout.js

//View
    <h3>Portfolio</h3>
<form data-bind="submit: addpf">
Add Portfolio: <input data-bind="value: newpf" placeholder="Who needs to be added?" />
    <button type="submit">Add</button>
</form>

<ul data-bind="foreach: pf, visible: pf().length > 0">
    <li>
        <input type="checkbox" data-bind="checked: isDone" />
        <input data-bind="value: title, disable: isDone" />
        <a href="#" data-bind="click: $parent.removepf">Delete</a>
    </li> 
</ul>

You have <b data-bind="text: oldpf().length">&nbsp;</b> New Portfolios
<span data-bind="visible:  oldpf().length == 0"></span>


//ViewModel


function pf(data) {
        this.title = ko.observable(data.title);
        this.isDone = ko.observable(data.isDone);
    }

    function pfListViewModel() {
        // Data
        var self = this;
        self.pf = ko.observableArray([]);
        self.newpf = ko.observable();
        self.oldpf = ko.computed(function() {
            return ko.utils.arrayFilter(self.pf(), function(pf) { return !pf.isDone() });
        });

        // Operations
        self.addpf = function() {
            self.pf.push(new pf({ title: this.newpf() }));
            self.newpf("");

        };
        self.removepf = function(pf) { self.pf.remove(pf) };
    }

    ko.applyBindings(new pfListViewModel());


Source: mysql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.