项目作者: kurtisdunn

项目描述 :
Quick Add/Remove table row example for KnockoutJS using ES6 classes.
高级语言: JavaScript
项目地址: git://github.com/kurtisdunn/KnockoutJS-Webpack-ES6.git
创建时间: 2016-12-09T04:56:54Z
项目社区:https://github.com/kurtisdunn/KnockoutJS-Webpack-ES6

开源协议:

下载


KnockoutJS Webpack ES6

Quick Add/Remove table row example for KnockoutJS using ES6 classes.

Build it

  1. webpack

Developing it:

  1. npm run dev

Example

  1. import './scss/main.scss';
  2. import ko from 'knockout';
  3. class PeopleViewModel{
  4. constructor(){
  5. //Inital data
  6. this.people = ko.observableArray([
  7. { name: 'John Smith', amount: 12.01 },
  8. { name: 'Jeff Smithe', amount: 0.50 },
  9. { name: 'Jarrod Smythe', amount: 1.00 }
  10. ]);
  11. //Bound remove to the constructor as $parent changes the context of this in ES6 classes.
  12. this.removePerson = value => { this.people.remove(value); };
  13. }
  14. addPerson(){
  15. //Get Value from text inputs.
  16. let name = document.getElementsByName('name')[0].value;
  17. let amount = document.getElementsByName('amount')[0].value;
  18. if(name !== undefined && amount !== undefined){
  19. //Add to ko array
  20. this.people.push({ name: name, amount: amount });
  21. }
  22. }
  23. }
  24. ko.applyBindings(new PeopleViewModel());