码迷,mamicode.com
首页 > Windows程序 > 详细

KnockoutJS 3.X API 第四章 数据绑定(5) 控制流component绑定

时间:2016-10-06 12:51:16      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

本节目录:

  • 一个例子
  • API
  • component生命周期
  • 备注1:仅模板式的component
  • 备注2:component虚拟绑定
  • 备注3:传递标记到component绑定
  • 内存管理

一个例子

First instance, without parameters

Second instance, passing parameters

UI源码:

<h4>First instance, without parameters</h4>
<div data-bind=‘component: "message-editor"‘></div>
 
<h4>Second instance, passing parameters</h4>
<div data-bind=‘component: {
    name: "message-editor",
    params: { initialText: "Hello, world!" }
}‘></div>

视图模型源码:

ko.components.register(‘message-editor‘, {
    viewModel: function(params) {
        this.text = ko.observable(params && params.initialText || ‘‘);
    },
    template: ‘Message: <input data-bind="value: text" /> ‘
            + ‘(length: <span data-bind="text: text().length"></span>)‘
});
 
ko.applyBindings();

下午继续更

KnockoutJS 3.X API 第四章 数据绑定(5) 控制流component绑定

标签:

原文地址:http://www.cnblogs.com/smallprogram/p/5933545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!