BreezeJS的二元谓词问题的左侧

时间:2017-01-30 22:10:55

标签: javascript knockout.js breeze model-binding

我使用BreezeJS遇到过滤谓词的问题。当我为过滤器集的一个特定过滤器赋值时,我得到客户端(浏览器)错误:'二元谓词的左侧不能是文字表达式,它必须是有效属性或功能谓词表达:'

我也在使用KnockoutJS,并且我有一些辅助函数来将谓词放在一起,但是,我没有做任何与这个特定过滤器无关的工作。

我已经将这个谓词与从不同的过滤器中创建的谓词进行了比较,据我所知,这两个谓词在它们应该是的方式上是相同的,我不会这样做。看到任何不应存在的差异。一个SME建议检查我的外壳,但是,这不是问题(我可以告诉) - IOW,db和视图模型之间的外壳是一致的。有没有人有建议?

代码:

这是由breeze控制器发送的元数据,对于不起作用的过滤器(GoofyGuy),以及那样做的那个,所以你可以看到元数据基本相同

{
 "name": "GoofyGuy",
 "type": "Edm.String",
 "nullable": "false",
 "maxLength": "256",
 "fixedLength": "false",
 "unicode": "true"
},
{
 "name": "Priority",
 "type": "Edm.String",
 "nullable": "false",
 "maxLength": "256",
 "fixedLength": "false",
 "unicode": "true"
},

这是html绑定:

<select data-bind="value: GoofyGuy().filterValue">
  <option value="">Select</option>
  <option>Approval Hold</option>
  <option>Approved</option>
  <option>Deleted</option>
  <option>Executed</option>
  <option>Execution Hold</option>
  <option>Off Hold</option>
  <option>Submitted</option>
  <option>Verification Hold</option>
  <option>Verified</option>
 </select>

以下是模型:

function Filter_ChangeRequest(canViewOthers) {
var self = this;
self.filterName = '',
self.filterType = 'changeRequest',
    self.dateCreated = ko.observable('');
self.isActive = ko.observable(true),
self.submitter = ko.observable(new FilterValue()),
self.deadline = ko.observable(new FilterComparison()),
self.priority = ko.observable(new FilterValue()),
self.GoofyGuy = ko.observable(new FilterValue()),
self.requestId = ko.observable(new FilterValue()),
self.itemTitle = ko.observable(new FilterValue()),
self.domain = ko.observable(new FilterValue()),
self.policyWaiver = ko.observable(new FilterValue()),
self.submitDate = ko.observable(new FilterComparison()),
self.approvedBy = ko.observable(new FilterValue()),
self.description = ko.observable(new FilterValue()),
self.canViewOthers = canViewOthers,
self.submitters = ['amr\\maburke', 'amr\\jdkraft'],
self.idsid = '';

self.setInitialValues = function () {
    self.submitter(new FilterValue('SubmittedByIdsid'));
    self.deadline(new FilterComparison('DeadlineRequested'));
    self.priority(new FilterValue('Priority'));
    self.GoofyGuy(new FilterValue('GoofyGuy'));
    self.requestId(new FilterValue('RequestId'));
    self.itemTitle(new FilterValue('Title'));
    self.domain(new FilterValue('Domain'));
    self.policyWaiver(new FilterValue('IncludesPolicyWaiver'));
    self.submitDate(new FilterComparison('SubmitDate'));
    self.approvedBy(new FilterValue('ApprovedBy'));
    self.description(new FilterValue('Description'));
    self.submitters = ['amr\\maburke', 'amr\\jdkraft'];
};

self.init = function () {
    self.setInitialValues();


};
self.clear = function () {
    self.setInitialValues();
};

self.populate = function (filterValues) {
    if (self.canViewOthers)
        self.submitter().populate(filterValues.submitter);
    self.deadline().populate(filterValues.deadline);
    self.priority().populate(filterValues.priority);
    //self.GoofyGuy().populate(filterValues.GoofyGuy);
    self.requestId().populate(filterValues.requestId);
    self.itemTitle().populate(filterValues.itemTitle);
    self.domain().populate(filterValues.domain);
    self.policyWaiver().populate(filterValues.policyWaiver);
    self.submitDate().populate(filterValues.submitDate);
    self.approvedBy().populate(filterValues.approvedBy);
    self.description().populate(filterValues.description);
};

self.breezeFilter = function () {
    var filterPredicates = ko.observableArray([]);
    //breezeUtils.addPredicate(self.submitter(), filterPredicates);
    //breezeUtils.addPredicate(self.deadline(), filterPredicates);

    //if (self.stateX().filterValue() == '')
    //    //add != Deleted predicate
    //    filterPredicates.push(breeze.Predicate.create('StateNameX', breeze.FilterQueryOp.NotEquals, 'Deleted'));
    //else
    breezeUtils.addPredicate(self.GoofyGuy(), filterPredicates);
    //breezeUtils.addPredicate(self.priority(), filterPredicates);
    //breezeUtils.addPredicate(self.itemTitle(), filterPredicates);
    //breezeUtils.addPredicate(self.domain(), filterPredicates);
    //breezeUtils.addPredicate(self.policyWaiver(), filterPredicates);
    //breezeUtils.addPredicate(self.submitDate(), filterPredicates);
    //breezeUtils.addPredicate(self.approvedBy(), filterPredicates);
    //breezeUtils.addPredicate(self.description(), filterPredicates);
    //breezeUtils.addPredicate(self.requestId(), filterPredicates);

    return breeze.Predicate.and(filterPredicates());

}
};

然后这些是弹出谓词的辅助函数:

var breezeUtils = {
Predicate: breeze.Predicate,
FilterQueryOp: breeze.FilterQueryOp,
addPredicate: function (filter, predicateCollection) {
    if (filter.filterValue()) {
        //if there is a filter value, add it to the predicate collection
        predicateCollection.push(this.getPredicate(filter));
    }
},
getPredicate: function (filter) {
    if (filter.hasOwnProperty('boundary') && filter.boundary()) { //compound predicate
        var p1 = this.Predicate.create(filter.title, this.FilterQueryOp.GreaterThanOrEqual, filter.filterValue());
        var p2 = this.Predicate.create(filter.title, this.FilterQueryOp.LessThanOrEqual, filter.boundary());
        return this.Predicate.and([p1, p2]);
    }
    var operator = this.getQueryOperator(filter.valueComparison());
    return this.Predicate.create(filter.title, operator, filter.filterValue());
},

最后,这是谓词集在被发送到服务器之前说明两个过滤器基本相同:

enter image description here

在下面的评论中,我表示即使在更改服务器和客户端上的所有内容以使用“傻瓜”之后,我仍然会收到相同的错误: enter image description here

1 个答案:

答案 0 :(得分:0)

套装 在GoofyGuy和其他所有内容之间看起来不同。 E.g:

self.priority(new FilterValue('Priority'));
self.GoofyGuy(new FilterValue('GoofyGuy'));

我认为Breeze正在使用名称(使用NamingConvention),然后尝试匹配(客户端)属性名称。所以:

"Priority" -> priority // works
"GoofyGuy" -> goofyGuy // Breeze can't find the property

self.GoofyGuy更改为self.goofyGuy,这应该可以解决问题。