我有一个简单的任务,事实证明并非如此简单。我需要复制一个angular.copy()
变量,而不使用newVal
,因为如果我使用复制功能,如果进行了更改,则无法将对象与观察者if (newVal !== original)
进行比较,因为它不是同一个对象。因此false
永远不会评估为core.directive('saveButton', function () {
return {
scope: {
actionParams: '=',
},
templateUrl: 'app/views/components/core/save-button.html',
link: function(scope, element, attrs) {
var original = scope.actionParams;
scope.$watch(function() {
return scope.actionParams;
}, function(newVal, oldVal) {
// I want to check if the original value has changed, not the previous value
if (newVal !== original) {
scope.changed = true;
}
else {
scope.changed = false;
}
}, true);
}
}
});
。如何存储范围变量的原始值,但永远不会再次更新此变量,即使范围变量发生变化也是如此?有可能吗?
<input type="checkbox" class="checkbox" id="smsflash" name="button_name">
答案 0 :(得分:2)
只存储json表示 - 它永远不会改变,你总是可以将它与新值的json表示进行比较。 https://docs.angularjs.org/api/ng/function/angular.toJson
或者您可以使用angular.equals比较对象:
ArrayAdapter adapter = new ArrayAdapter(PrescriptionsArrayActivity.this, android.R.layout.simple_list_item_1, arrayprescription);
lvPrescriptions.setAdapter(adapter);
ParseQuery<ParseObject> query = ParseQuery.getQuery("PrescriptionObject");
query.whereEqualTo("MedicalID", etMedicalID.getText().toString());
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> prescriptionList, ParseException e) {
if (e == null) {
final List<String> arrayprescription = new ArrayList<String>();
for (int i = 0; i < prescriptionList.size(); i++) {
ParseObject p = prescriptionList.get(i);
adapter.add(stateList.get(i));
}
&gt;&gt;真