我已经使用Easy Query Builder的演示应用程序将Easy Query Builder添加到我的MVC项目中,并根据演示项目添加了.css和.js文件。执行时 实体未加载,并且未调用构造函数和getModel()。加载页面后,EQ.Client未定义 这是我的代码。
EasyQuery.cshtml(查看)
<script type="text/javascript">
window.easyQuerySettings = {
serviceUrl: "/EasyQuery",
modelName: "NWindSQL",
entitiesPanel: { showCheckboxes: true },
columnsPanel: {
allowAggrColumns: true,
attrElementFormat: "{entity} {attr}",
showColumnCaptions: true,
adjustEntitiesMenuHeight: false,
menuOptions: {
showSearchBoxAfter: 30,
activateOnMouseOver: true
}
},
queryPanel: {
showPoweredBy: false,
alwaysShowButtonsInPredicates: false,
adjustEntitiesMenuHeight: false,
menuOptions: {
showSearchBoxAfter: 20,
activateOnMouseOver: true
}
},
syncQueryOptions: {
sqlOptions: { SelectDistinct: true }
},
};
function getPrefix() {
var res = window.location.pathname;
if (res.charAt(res.length - 1) !== '/')
res = res + '/';
return res;
}
</script>
<div class="entities-panel-container">
<div id="EntitiesPanel"></div>
</div>
<div class="columns-panel-container">
<div id="ColumnsPanel"></div>
</div>
<div class="query-panel-container">
<div id="QueryPanel"></div>
</div>
<script type="text/javascript">
**$(function () {
var query = EQ.client.getQuery();
EQ.client.loadModel({ modelName: "Model1" });
});**
</script>
EasyQuerycontroller.cs中的
public class **EasyQueryController** : Controller
{
private EqServiceProviderDb eqService;
public **EasyQueryController()**
{
eqService = new EqServiceProviderDb();
eqService.SessionGetter = key => Session[key];
eqService.SessionSetter = (key, value) => Session[key] = value;
eqService.StoreQueryInSession = true;
eqService.Formats.SetDefaultFormats(FormatType.MsSqlServer);
eqService.Formats.UseSchema = false;
string dataPath = System.Web.HttpContext.Current.Server.MapPath("~/App_Data");
eqService.DataPath = dataPath;
eqService.Connection = new SqlConnection("Data Source=" + System.IO.Path.Combine(dataPath, "Northwind.sdf"));
}
[HttpPost]
public ActionResult GetModel(string modelName)
{
var model = eqService.GetModel(modelName);
return Json(model.SaveToDictionary());
}
...
}
我应该更改一些代码还是包含一些其他功能来填充EQ.Client元素。?
答案 0 :(得分:2)
我看不到您在视图页面上实际包含EasyQuery脚本的位置。 在视图页面的末尾(关闭“body”标记之前)必须有类似以下标记的内容:
<script src="http://cdn.korzh.com/eq/3.6.0/eq.all.min.js" type="text/javascript"></script>
<script src="http://cdn.korzh.com/eq/3.6.0/eq.view.basic.js" type="text/javascript"></script>