【发布时间】:2014-10-31 22:52:19
【问题描述】:
我正在使用 jsView (v1.0.0-alpha)
我在从视图中获取数据时遇到问题。让我有以下代码。 (我在这里创建了一个简化版本 http://jsfiddle.net/j5oc0svg/ )我正在尝试使用占位符名称获取我之前绑定到视图的数据对象。它总是返回'undertified'。如果我调用 $.view().views 那么我可以看到我之前绑定的视图和数据。
如何使用占位符或(视图名称?)获取绑定到视图的数据?
提前致谢。
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.js"></script>
<base href="http://www.jsviews.com/samples/"/>
<link href="samples.css" rel="stylesheet"/>
<script src="../download/jsviews.js"></script>
</head>
<body>
<table><tbody id="peopleList"></tbody></table>
<script id="personTmpl" type="text/x-jsrender">
<tr>
<td>Name</td>
<td>{{:name}}</td>
</tr>
</script>
<script>
$.ajax({
url: "http://localhost:4728/api/People/,
dataType: 'json'
}).done(function (data) {
if (data!= null) {
var template = $.templates("#personTmpl");
template.link("#peopleList", data);
}
}).fail(function (exception) {
console.log(exception.message);
});
// Let's say this code is in button on click or push subscriber
hub_proxy.client.UpdateSomething = function (someArgs) {
var data = $.view('#peopleList').data; //underfined.
}
</script>
</body>
</html>
【问题讨论】:
-
你没有任何数据属性,所以数据属性是未定义的?
-
no.. 如果您查看此链接 (jsviews.com/#jsvplaying),它具有类似的代码。 $("#peopleList").on("click", ".changeBtn", function() { var dataItem = $.view(this).data; $.observable(dataItem).setProperty("name", dataItem. name + counter++); }).. "$.view(this.data)" 在没有 data 属性的情况下工作。
标签: javascript jquery-templates jsrender jsviews