[英]JsViews template for data-linked property editor
There's any way to achieve a "generic" property editor with JsViews? 有没有办法用JsViews实现“通用”属性编辑器? Let's see if I can explain myself: I'd like to have something roughly like this 让我们看看我是否可以自我解释:我想要大概这样的东西
<script type="text/x-jsrender">
{{include #data.property1 tmpl="#propeditor" /}}
{{include #data.property2 tmpl="#propeditor" /}}
{{include #data.property3 tmpl="#propeditor" /}}
</script>
<script type="text/x-jsrender" id="propeditor">
<div class="editableField">
<div>
<span class="[onClickHideMeAndShowTheDataLinkedInput]">
{^{>[ref to prop]}}
</span>
</div>
<input type="text" data-link="[prop name] trigger=true" style="display:none;" class="[onBlurShowThePlainTextAgain]" />
</div>
</script>
In other words, I want to create a somewhat dynamic data linking inside a template, to avoid code replication. 换句话说,我想在模板内部创建一个有点动态的数据链接,以避免代码复制。 Can this be done? 能做到吗?
Yes - you can do that. 是的,你可以这么做。 There is a sample on this documentation page: http://www.jsviews.com/#jsvviewobject . 该文档页面上有一个示例: http : //www.jsviews.com/#jsvviewobject 。 Look for Sample: view.childTags() . 查找示例:view.childTags() 。
It defines a {textbox}
tag which you can toggle between editable and non-editable: 它定义了一个{textbox}
标签,您可以在可编辑和不可编辑之间切换:
$.views.tags({
textbox: {
init: function() {
var path = this.tagCtx.params.props.path + " trigger=true";
this.template = "<input data-link='~tag.edit' type='checkbox'/> " // Checkbox to toggle edit
+ "<input data-link='visible{:~tag.edit} {:" + path + ":}'/>" // <input> for editing
+ "<span data-link='visible{:!~tag.edit} {:" + path + "}'></span>"; // <span> for rendering
},
toggleEdit: function() {
$.observable(this).setProperty("edit", !this.edit);
}
}
});
There is also a variant here https://github.com/BorisMoore/jsviews/issues/134#issuecomment-216694113 which uses switching of templates rather than visibility to toggle editability... 这里还有一个变体https://github.com/BorisMoore/jsviews/issues/134#issuecomment-216694113 ,它使用模板的切换而不是可见性来切换可编辑性...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.