JSView MVVM数据绑定库学习

MVVM js 库JsRender/JsViews和knockoutjs介绍


http://www.oschina.net/p/jsrender

konckoutjs 参见前端开发框架Bootstrap和KnockoutJS

backbase 框架使用 (songjian公司)


jsViews官网

简书:


使用:

map

List<String> 直接用data表示{{:#data}}  {{:index}}   或者 {{:}} 表示数据

List<Bean>  {{for ...}}

if

{{if nullAble==0}}可以为空{{else}}不能为空{{/if}}

自定义转换器或者tags 

$.views.converters

{{subStrings:username lens=5}}
<img src="../../{{firstImgs:shopProductPicUrls}}"/>
<td>
	<%--photos是用逗号间隔的字符串--%>
	{{if photos}}
	{{for photos.split(",")}}
		 <img layer-src="../../{{:}}" layer-pid="" src="../../{{:}}" alt="" layer-index="0" height="40" width="50">
			{{/for}}
	{{else}}
	{{/if}}
</td>
bool:
<select class="form-control input-sm" id="isHot" name="type" data-rule="required" >
         <option  value="">请选择</option>
         <option  value="1" {{if isHot==true}}selected{{/if}}>热点</option>
         <option  value="0" {{if isHot==false}}selected{{/if}}>普通</option>
 </select>



helpers
{{:~myHelperValue}}
{{:~myHelperFunction(name, title)}}
{{for ~myHelperObject.mySortFunction(people, "increasing")}} ... {{/for}}
debug模式


使用原生的js写法:
{{if detail.length>20}}{{:detail.substring(0,20)}}......{{else}}{{:detail}}{{/if}}

Bindable.js 实现了灵活、快速的双向数据绑定的 JavaScript 。 Two-way data binding means linking properties of two separate objects - when one changes, the other will automatically update with that change.  It enables much easier interactions between data models and UIs, among other uses outside of MVC. Bindable.js is similar to Ember's data-binding system, except it doesn't include anything View related, so the library has many use-cases - whether replacing Backbone's Model, providing a way to maintain the state between server <-> client for a realtime front-end application (similar to Firebase), or perhaps a way to communicate between server <-> server for a realtime distributed Node.js application. Projects using bindable.js Paperclip.js - data-bindable templating engine. Sherpa.js - online tours library Mojo.js - javascript MVC framework. AWSM - aws library. ditto - synchronized user interactions across browsers. 示例代码: var bindable = require("bindable"); var person = new bindable.Object({   name: "craig",   last: "condon",   location: {     city: "San Francisco"   } }); person.bind("location.zip", function(value) {   // 94102 }).now(); //triggers the binding person.set("location.zip", "94102");  //bind location.zip to another property in the model, and do it only once person.bind("location.zip", { to: "zip", max: 1 }).now(); //bind location.zip to another object, and make it bi-directional. person.bind("location.zip", { target: anotherModel, to: "location.zip", bothWays: true }).now(); //chain to multiple items, and limit it! person.bind("location.zip", { to: ["property", "anotherProperty"], max: 1 }).now(); //you can also transform data as it's being bound person.bind("name", {   to: "name2",   map: function (name) {     return name.toUpperCase();   } }).now(); 标签:Bindable
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值