示例#1
0
QUnit.test("create an observable let scope (#593)", function(){
	var template = stache("<div>{{# for(thing of this.stuff)}}"+
		"{{let theValue=null}}"+
		"{{write theValue}}"+
		"<label>{{theValue}}</label>"+
    "{{/ for}}</div>");

	var obs = [];
	var frag = template({
		stuff: [{},{}],
		write: function(theValueObservable){
			obs.push(theValueObservable);
		}
	});

	canReflect.setValue( obs[0] , 1);
	canReflect.setValue( obs[1] , 2);

	var labels = frag.firstChild.getElementsByTagName("label");

	QUnit.equal(labels[0].innerHTML,"1", "first element");
	QUnit.equal(labels[1].innerHTML,"2", "first element");


});
			function setViewModelProperty(newVal) {
				var viewModel = bindingContext.viewModel;

				if (setCompute) {
					// If there is a binding like `foo:from="~bar"`, we need
					// to set the observable itself.
					var oldValue = canReflect.getKeyValue(viewModel, setName);
					if (canReflect.isObservableLike(oldValue)) {
						canReflect.setValue(oldValue, newVal);
					} else {
						canReflect.setKeyValue(
							viewModel,
							setName,
							new SimpleObservable(canReflect.getValue(newVal))
						);
					}
				} else {
					if (isBoundToContext) {
						canReflect.setValue(viewModel, newVal);
					} else {
						stacheKey.write(viewModel, keysToRead, newVal);
					}
				}
			}
			set: function( newVal, fooCompute ) {
				canReflect.setValue(fooCompute, (""+newVal).toUpperCase() );
			}
示例#4
0
		}, set: function(val, valCompute) {
			return canReflect.setValue(valCompute, parseInt("0x" + val));
		}
示例#5
0
QUnit.test("can-reflect setValue", function(){
	var a = compute("a");

	canReflect.setValue(a, "A");
	QUnit.equal(a(), "A", "compute");
});
					"can.setValue": function setValue(newVal) {
						var expr = expression.parse(cleanVMName(scopeProp, scope),{baseMethodType: "Call"});
						var value = expr.value(scope);
						canReflect.setValue(value, newVal);
					},